Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a menu page from which a user selects a particular item .Depending on the item's(product) name,specifications for that product should be displayed .My datebase(Sql) contains the specfications details ..The code below when executed shows error at "dap.Fill(ds)"..In case my question is not reached to you ,then think of a online shopping site ,whenever user selects a particular item, details of the product ,pictures should be shown in another page..How can i achieve this using asp.net nd grid view ..Pls help me out asap .
C#
{
String store = Request.QueryString["id"];

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select spec from computer where prod_name is '"+store+"' ";
cmd.Connection = con;
DataSet ds = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
con.Close();
}

.
Posted
Updated 15-Apr-13 0:42am
v2

It may look funny but try executing following way

C#
{
String store = Request.QueryString["id"];
 
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select spec from computer where prod_name is '"+store+"' ";
DataSet ds = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(cmd.CommandText,con);
dap.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
con.Close();
} 


Hope it helps you...
 
Share this answer
 
v2
C#
{
String store = Request.QueryString["id"];
 
SqlCommand cmd = new SqlCommand("select spec from computer where prod_name is '"+store+"' ");

DataSet ds = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(cmd,con);
dap.Fill(ds,"TableName");
GridView1.DataSource = ds;
GridView1.DataMember=ds.Tables[0].tableName;
GridView1.DataBind();
con.Close();
}


[edit]Code block added[/edit]
 
Share this answer
 
v2
Comments
fjdiewornncalwe 15-Apr-13 9:19am    
My 1. Never, ever, ever use inline concatenated strings in a query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900