how to connect Sql database in ASP.NET?

Saed G

New member
im new to ASP.NET and i made a table and put some data in it to test it ... and i made a text box and a button , i want to search the database and retrieve the information in a grid view !!

here's my code

SqlConnection q1 = new SqlConnection(SqlDataSource1.ConnectionString);
SqlCommand cmd1 = new SqlCommand("SELECT * FROM [Drs] WHERE ([Name] = @Name) ", q1);

cmd1.Parameters.AddWithValue("@Name", TextBox1.Text);

q1.Open();
SqlDataReader dr = cmd1.ExecuteReader();

/// of course i put the Using System.Data.Sqlclient ;

but there's nothing appears in the grid view

im using VS2010
 
Throw a try catch block on this line
SqlDataReader dr = cmd1.ExecuteReader();
and a break point and step throguh and see if it is throwing an error and you can see what that error is.
 
Back
Top