我有这个存储过程并且工作得很好,但我需要从 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