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我要搜索的用户输入的内容数据库,并显示单词
==当我搜索字车应显示所有与汽车的字符串和dfgsd,sdkgs将不会显示
查询工作,就像我在EXP让SQL服务器显示,但我不知道在哪里把它放在C#中的代码,当我点击按钮时,它不显示任何东西,即使没有记录发现作为错误处理程序
调试你的代码,并把就行'串SqlInsertStatement'一个破发点,然后单步运行线和捕捉变量'SqlInsertStatement'值。将该查询复制并粘贴到SQL Server Management Studio并运行它,我打赌你会得到一个错误。最后,在您的问题和帮助中发布该查询。 :-) –
希望没有人在文本框中键入'%'DROP DATABASE试用版--': –
我试图调试它并放置了几个断点,它只到达这一行“if(Request.QueryString [TextBox1.Text] != null)“并停止 – deniel