Sir, I hv a pgm in which I want search an item from gridview and displayed on textboxes,if the item number is "c12", then if I type "c" then the grid will display all item starting with c, but nw it shows error it shows only c12 , remaining is not showing, initially the pgm work, but nw it shows this pblm
This is my code
{
String str = "select * from MyMast where (CODE like + @search + '%')ORDER BY CODE ASC;";
SqlCommand xp = new SqlCommand(str, con);
xp.Parameters.Add("@search", SqlDbType.VarChar).Value = TextBox1.Text;
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
DataSet ds = new DataSet();
da.Fill(ds, "CODE");
GridView1.DataSource = ds;
GridView1.DataBind();
}
Rahul SinghPosted Dec 24, 2014, 1:04 AM
Your question is not pretty clear, as if the whole grid column is missing or only the data is missing, I would strongly recommend you to modify your code like below, because your code have SQL Injection attack threat, plus you should always wrap your code inside using block to automatically dispose the expensive resources.
string CS = "Your connection string";
using (SqlConnection con = new SqlConnection(CS))
{
string str = "SELECT * FROM MyMast WHERE CODE LIKE @search ORDER BY CODE ASC;";
using (SqlDataAdapter da = new SqlDataAdapter(str, con))
{
da.SelectCommand.Parameters.Add("@search", SqlDbType.VarChar).Value = "%" + TextBox1.Text + "%";
DataSet ds = new DataSet();
da.Fill(ds, "CODE");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Khargesh RajputPosted Dec 24, 2014, 12:56 AM
Query is right.
may be data not present in database.
close your connection
and debug