qq_33854564
qq_33854564
2016-01-26 05:49
采纳率: 50%
浏览 1.8k
已采纳

求各位大神看一下,运行时查询结果只显示一行

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();
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • showbo
    已采纳

    TextBox.Text += myReader.GetValue(i).ToString();

    点赞 评论
  • qq_33854564
    qq_33854564 2016-01-26 06:02

    这样改了之后说 SqlDataReader myReader = sqlCmd.ExecuteReader();在关键字 'where' 附近有语法错误。

    点赞 评论

相关推荐