Just Try this one
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)<br /> { <br /> DataSet Ds=new DataSet();<br /> con = new SqlConnection("Data Source=.;Initial Catalog=abc;Integrated Security=True");<br /> cmd = new SqlCommand("select * from salescounts where ='"+DropDownList1.Text+"'", con);<br /> SqlDataAdapter DA = new SqlDataAdapter(cmd);<br /> DA.Fill(ds); <br /> if(Ds.Tables[0].Rows.Count>0)<br /> {<br /> GridView1.DataSource = ds;<br /> GridView1.DataBind();<br /> Label1.Text = "Result found:" + GridView1.Rows.Count;<br /><br /> }<br /> else<br /> {<br /> Label1.Text = "not found";<br /> }<br /><br /> con.Close();<br /> <br />}
Quick Suggestion :solo_gaurav wrote:
cmd = new SqlCommand("select * from salescounts where ='"+DropDownList1.Text+"'", con);
Never Execute SQL Query like this from UI level. It will causes SQL Injection. Always used Parameterized query / Stored Procedure .
Thansk :-D