【发布时间】:2016-02-22 11:11:10
【问题描述】:
我是一名初级开发人员,我仍在学习,目前我遇到了一个错误。我正在学习如何制作正确的sqlconnections.. 的新技术,但似乎我无法找出问题所在。
这是一个简单的程序,用户正在扫描条形码以填充文本框。并取决于该值。其余的文本框将被填写。
System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的异常,但未在用户代码中处理。附加信息:“ProductBarcode”附近的语法不正确。
这是我现在的代码:
protected void PBarcodeTxt_TextChanged(object sender, EventArgs e)
{
string cmd = "SELECT ProductNaam, ProductPrijs, ProductOmschrijving, ProductBarcode" +
"FROM Producten" +
"WHERE ProductBarcode LIKE '@Barcode'";
using (SqlConnection connection = new SqlConnection(cstring))
{
SqlCommand command = new SqlCommand(cmd, connection);
command.Parameters.Add("@Barcode", SqlDbType.VarChar, 50).Value = PBarcodeTxt.Text;
try
{
connection.Open();
SqlDataReader rdr = command.ExecuteReader();
rdr.Read();
PNaamTxt.Text = (rdr["ProductNaam"].ToString());
POmschrijvingTxt.Text = (rdr["ProductOmschrijving"].ToString());
PPrijsTxt.Text = (rdr["ProductPrijs"].ToString());
// PBarcodeTxt.Text = (rdr["ProductBarcode"].ToString());
}
finally
{
connection.Close();
}
感谢您的时间和精力。
【问题讨论】: