0
我想從DB2數據庫調用Visual Basic中的存儲過程。我想從我的Visual Basic代碼中將一個變量的輸入作爲參數發送出去,並將輸出放入我的VB代碼中的變量中。這裏是我的存儲過程的代碼:如何使用Visual Basic調用DB2存儲過程?
CREATE PROCEDURE VendorPROCEDURE (IN p_vendor_name VARCHAR(50),
OUT p_name VARCHAR(25),
OUT p_company_name VARCHAR(50),
OUT p_address VARCHAR(25),
OUT p_csz VARCHAR(50),
OUT p_phone CHAR(13))
DYNAMIC RESULT SETS 1
P1: BEGIN
DECLARE v_name VARCHAR(25);
DECLARE v_company_name VARCHAR(50);
DECLARE v_address VARCHAR(25);
DECLARE v_csz VARCHAR(50);
DECLARE v_phone CHAR(13);
SELECT RTRIM(REP_F_NAME || ' ' || REP_L_NAME), COMPANY_NAME, STREET,
RTRIM(CITY || ', ' || STATE || ' ' || VENDOR.ZIP_CODE) AS CSZ, PHONE_NUM
INTO v_name, v_company_name, v_address, v_csz, v_phone
FROM SALES_REP, VENDOR, ZIP
WHERE SALES_REP.REP_NUM = VENDOR.REP_NUM
AND ZIP.ZIP_CODE = VENDOR.ZIP_CODE
AND COMPANY_NAME = p_vendor_name;
SET p_name = v_name;
SET p_company_name = v_company_name;
SET p_address = v_address;
SET p_csz = v_csz;
SET p_phone = v_phone;
END P1
在我的VB代碼,我導入的IBM.Data.DB2,這裏是我的代碼至今:
Dim vendorName As String
vendorName = Vendor_ComboBox.Text
cmd = connectionstring.CreateCommand()
connectionstring.Open()
Dim trans As DB2Transaction = connectionstring.BeginTransaction()
cmd.Transaction() = trans
Dim reader As DB2DataReader
Dim procName As String = "VENDORPROCEDURE"
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = procName
我不知道在哪裏從那裏出發。
從這裏出發?嘗試添加'cmd.Execute'。另外,VB與VBA不同。後者主要運行在MS Office產品中。請相應標記。 – Parfait
首先添加您的參數param = new sqlparameter(「p_vendor_name」,)param.direction =輸入cmd.parameters.add(param)等等,改變輸出參數的方向 –