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条回答 默认 最新

相关推荐 更多相似问题