4
Answers

Problem while fetching records from sql server database

Ankit Kumar

Ankit Kumar

8y
321
1
Dear Friends........
 
I facing a problem while trying to fetch records from sql server database in asp .net website
 
i am using gridview control to show the records.............
 
my project file is attached in as a zip 
 
 

Attachment: webdata.zip

Answers (4)
0
Ankit Kumar

Ankit Kumar

NA 152 10.8k 8y
hi Raj,
i had made a configuration related mistake and i have resolved it myself
0
Gokul Raj

Gokul Raj

NA 270 963 8y
hi
Please share your error screen shot.
0
Ankit Kumar

Ankit Kumar

NA 152 10.8k 8y
Hi Raj,
It's not working.........
0
Gokul Raj

Gokul Raj

NA 270 963 8y
Hi
Please use the below code in getdata.aspx.cs.,I hope it will work for you.
SqlConnection connec = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
connec.Open();
SqlCommand cmd = new SqlCommand("select * from Product_Detail where Product_Id=@pid", connec);
cmd.Parameters.Add("@pid", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem.Value;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}