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