0
我正在从数据库中进行搜索。用户将输入字符串。这个字符串将被转换成数组,然后这个数组索引值将从表中检查以找到匹配。 我正在使用循环遍历数组查询执行是在该循环中,它的罚款,但如果有多个索引来搜索它显示最后索引搜索值。 我知道这不是一个正确的搜索方式。在一个查询中从数据库搜索多个数组索引值
我该怎么做。
SqlConnection conOpen;
string[] arrayList;
protected void Page_Load(object sender, EventArgs e)
{
DataLayer datalayer = new DataLayer();
conOpen = datalayer.connectionOpen();
string myString = Request.QueryString["searchText"].ToString();
char[] separator = new char[] { ' ' };
arrayList = myString.Split(separator);
for (int i = 0; i <= arrayList.GetUpperBound(0); i++)
{
Response.Write(arrayList[i]);
string asd = arrayList[i];
String arrayQuery = "Select * from tbl_products where product_name LIKE '%" + @asd + "%'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(arrayQuery, conOpen);
da.Fill(ds, "tbl_products");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
'索引在数组的界限之外'使用**的错误** –
正确...复制了他的循环代码。使用<。谢谢 –
'关键字'LIKE'附近的语法不正确,你的代码看起来不错,但我不知道为什么它没有显示任何结果 –