[英]How set a variable in Mysql from Visual Basic .net using parametrized Value from a Texbox
我有此存儲過程,工作正常,但我需要從Visual Basic .net傳遞變量“ @item”,代碼可使用直接查詢來工作,但由於雜亂和不安全,我需要參數化,並從文本框中發送值。
SET @item = '@vbitem';
SELECT
rm_users.username,
rm_users.enableuser,
rm_users.firstname,
rm_users.lastname,
rm_users.company,
rm_users.phone,
rm_users.mobile,
rm_users.address,
rm_users.city,
rm_users.srvid,
rm_users.staticipcpe,
rm_users.contractid,
rm_users.email,
radacct.nasipaddress,
radacct.callingstationid,
radacct.framedipaddress,
rm_wlan.maccpe,
rm_wlan.ccq,
rm_wlan.`signal`,
rm_wlan.snr,
rm_wlan.apip,
rm_wlan.`timestamp`,
nas.nasname,
nas.shortname,
radacct.acctstoptime
FROM
rm_users
INNER JOIN radacct ON rm_users.username = radacct.username
INNER JOIN rm_wlan ON radacct.callingstationid = rm_wlan.maccpe
INNER JOIN nas ON radacct.nasipaddress = nas.nasname
WHERE
rm_users.username LIKE @item OR
rm_users.firstname LIKE @item OR
rm_users.lastname LIKE @item OR
rm_users.city LIKE @item OR
rm_users.address LIKE @item OR
rm_users.taxid LIKE @item OR
rm_users.company LIKE @item OR
radacct.callingstationid LIKE @item
GROUP BY
rm_users.username
ORDER BY
rm_users.username ASC here
Visual Basic代碼提取
cmd = New MySqlCommand("procedure-name")
cmd.Parameters.AddWithValue("@vbitem", textbox.Text)
cmd.CommandType = CommandType.StoredProcedure
如果您的存儲過程具有@item
參數,則應刪除存儲過程中的第一行,然后在VB代碼中設置@item
參數,即
cmd.Parameters.AddWithValue("@item", textbox.Text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.