[英]Searched data not loading to the data grid view in asp.net form?
當我點擊搜索時,它將在表格中按名稱搜索。(參考圖片 1)
我的搜索代碼
protected void srchbtn_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(this.TextBox1.Text))
{
Response.Write("<script>alert('Search name is empty!')</script>");
}
else
{
con.Open();
adapt = new SqlDataAdapter("select Convert(nvarchar(10),Date,121) as Date,Department,KaizenLead,Type,Observation,Onetimereapeat,Typeofwaste,Rootcase,ImageBefore,ImageAfter,Before,After,Improvement,Savings,Impleteam,validateby,Rootcase,safetyadmin,convert(nvarchar(10),Implementationdate,121) as Implementationdate,Status,Reason,FinanceRef from GembaKaizen where KaizenLead like '" + TextBox1.Text + "'", con);
dt = new DataTable();
adapt.Fill(dt);
gv_case.DataSource = dt;//gv_gase-grid view name
con.Close();
}
}
catch(SqlException)
{
Response.Write("<script>alert('Database error!')</script>");
}
}
con.Open();
adapt = new SqlDataAdapter("select Convert(nvarchar(10),Date,121) as Date,Department,KaizenLead,Type,Observation,Onetimereapeat,Typeofwaste,Rootcase,ImageBefore,ImageAfter,Before,After,Improvement,Savings,Impleteam,validateby,Rootcase,safetyadmin,convert(nvarchar(10),Implementationdate,121) as Implementationdate,Status,Reason,FinanceRef from GembaKaizen where KaizenLead like '" + TextBox1.Text + "'", con);
DataSet ds = new DataSet();
adapt.Fill(ds);
gv_case.DataSource = ds;
gv_case.DataBind();
con.Close();
我不確定我是否理解這個問題,但我可以看到您的代碼有兩個問題:
%
否則就是相等like '%" + TextBox1.Text + "%'"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.