public string[] ResultsQuery;
public int i;
public string criteria;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connString = @"Data Source=ITLAPTOP\SQLEXPRESS;Initial Catalog=trial;Integrated Security=True";
SqlConnection connStudent = new SqlConnection(connString);
connStudent.Open();
if (Request.QueryString[TextBox1.Text] != null)
{
ResultsQuery = Request.QueryString[TextBox1.Text].Split(' ');
foreach (string textbox1 in ResultsQuery)
{
if (!string.IsNullOrEmpty(criteria))
criteria += " OR ";
criteria += "SearchName LIKE '%" + textbox1 + "%' ";
}
string SqlInsertStatement = @"select * from trial.dbo.Student where Student.SearchName where '" + criteria;
SqlCommand cmdTxt = new SqlCommand(SqlInsertStatement, connStudent);
SqlDataReader dtrACode = cmdTxt.ExecuteReader();
dtrACode.Read();
try
{
if ((dtrACode["SearchName"].ToString().Trim().Length != 0))
{
}
ListBox1.Items.Add(dtrACode["SearchName"].ToString());
}
catch (Exception)
{
ListBox1.Items.Add("NO RECORD FOUND!");
}
connStudent.Close();
connStudent.Dispose();
}
}
我想显示用户输入的关键字的所有出现,例如数据库中的列表:abCARdfg CARsdg CAR dfgsd sdkgs
== 当我搜索单词 CAR 时,应显示所有带有 CAR 的字符串,并且不会显示 dfgsd,sdkgs
查询的工作方式就像我期望 SQL 服务器显示的那样,但我不知道将它放在 c# 代码中的位置,当我单击按钮时,它不显示任何内容,即使是作为错误的 NO RECORD FOUND处理程序