如何链接文本框?
场景:
TextBox_Supplier
TextBox_Address
TextBox_Supplier
是自动完成的并且正在工作。在 TextBox_Supplier
中完成输入后,TextBox_Address
将选择供应商的地址。
我的代码不起作用:
private void txb_vendor_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txb_address.Text))
{
PurCon.con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = PurCon.getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = String.Format("SELECT address FROM tbl_Supplier WHERE supplier_name = {0}",txb_vendor.Text);
SqlDataReader red = cmd.ExecuteReader();
while (red.Read())
{
string address = red.GetString(0);
address = txb_address.Text;
}
PurCon.con.Close();
}
}
谢谢你帮助我!
最佳答案
而不是
address = txb_address.Text;
写
txb_address.Text = address;
尝试使用参数化查询而不是字符串连接。
关于c# - 链接文本框 C# SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40396222/