I want search a item frome database

Posted by vishal on Stack Overflow See other posts from Stack Overflow or by vishal
Published on 2012-09-15T09:34:28Z Indexed on 2012/09/15 9:37 UTC
Read the original article Hit count: 147

Filed under:

I want search a item frome database bye date and id but if I want to search only by date or id tahn data are display but if I want to search by both date and id than not both are display but combine both and than display.

my code:

SqlConnection con = new SqlConnection("Data Source=NODE5-PC;Initial Catalog=hans;Persist Security Info=True;User ID=sa;Password=123");
cmd = new SqlCommand("SELECT UserId, Date, Report FROM Daily_Report WHERE (Date='" + txtdate.Text + "' or UserId='" + txtempid.Text + "') OR (UserId='" + txtempid.Text + "' and UserId='" + txtempid.Text + "')", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
GridView2.DataSource = rdr;
GridView2.DataBind();

 con.Close();

© Stack Overflow or respective owner

Related posts about ASP.NET