Skip to content Skip to sidebar Skip to footer

Binding Sqldatareader To Gridview C#

I am creating an application for a asp.net class that I am taking. One of the pages in the application needs to allow a user to search for a specific student via last name or user

Solution 1:

Try this out:

 SqlConnection connection = new SqlConnection();
 connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
 SqlCommand command = new SqlCommand(sqlSelectFindUserByName);

 connection.Open();
 command.Connection = connection;
 SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
 GridView1.DataSource = reader;
 GridView1.DataBind();

Post a Comment for "Binding Sqldatareader To Gridview C#"