问题描述
- 求各位大神看一下,运行时查询结果只显示一行
-
protected void wbtn_find_Click(object sender, EventArgs e)
{
string where = "";
string text = Textname.Text;
for (int i = 0; i < text.Length; i++)
{
string ss = text.Substring(0, 1);
where += "(District_Name LIKE '%" + ss + "%')";
if (i < text.Length - 1)
{
where += " OR ";
}
}
string str = @"SELECT District_Name, District_Code
FROM dbo.D_DISTRICT_MAST
WHERE " + where;
SqlConnection sqlCon = new SqlConnection("data source=.;database=HMMS;uid=sa;pwd=");SqlCommand sqlCmd = new SqlCommand(str, sqlCon); sqlCon.Open(); SqlDataReader myReader = sqlCmd.ExecuteReader(); while (myReader.Read()) { int i = 0; TextBox.Text = myReader.GetValue(i).ToString(); i++; } myReader.Close(); sqlCon.Close(); }
解决方案
TextBox.Text += myReader.GetValue(i).ToString();
解决方案二:
这样改了之后说 SqlDataReader myReader = sqlCmd.ExecuteReader();在关键字 'where' 附近有语法错误。
时间: 2025-01-15 16:15:14