从数据库搜索. [英] Searching from database.
本文介绍了从数据库搜索.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要在一个网页中进行搜索,该网页将通过一个文本框进行搜索,该文本框将获取值或ID,然后它将从数据库中搜索其所有相关信息.那么该怎么办呢?
最好的问候,
Golam kibria
Hi all,
I need to search in a web page that will search by a textbox that will get the value or id and then it will search all its relative information from database.So how can I do it?
Best Regards,
Golam kibria
推荐答案
我了解了您的问题
我给出了如下解决方案
As I Understood Ur Question
I Given Solution Like As Follows
<asp:textbox id="txt_Search" runat="server" width="200px">
<Button ID="btn_Search" runat="server" Text="Search" önclick="btn_Search_Click">
<br /><br />
<asp:textbox id="txt_Result" runat="server" textmode="MultiLine" width="200px" height="200px">
SqlConnection con = new SqlConnection("Ur Connection String");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Search_Click(object sender, EventArgs e)
{
try
{
con.Open();
string Query =
"Select UserName from Users Where UserName LIKE
''%" + txt_Search.Text + "%''";
SqlDataAdapter da = new SqlDataAdapter(Query, con);
DataTable DT = new DataTable();
da.Fill(DT);
txt_Result.Text = "";
for (int i = 0; i < DT.Rows.Count; i++)
{
txt_Result.Text += DT.Rows[i][0].ToString();
txt_Result.Text += " ";
}
if (txt_Result.Text == "")
txt_Result.Text = "No Result Found";
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
希望这对您有帮助
Hope This WIll Help You
这篇关于从数据库搜索.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文