This document demonstrates how to use an ADO.NET DataAdapter to populate a DataSet and bind it to an ASP.NET GridView control. It shows defining connection string and SQL command, creating a DataAdapter, filling a DataSet, and binding the DataSet to the GridView. It also shows calling a stored procedure and populating a DataTable from the returned DataAdapter.
Download as RTF, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
73 views
C# DataAdapter - SelectCommand With Parameters
This document demonstrates how to use an ADO.NET DataAdapter to populate a DataSet and bind it to an ASP.NET GridView control. It shows defining connection string and SQL command, creating a DataAdapter, filling a DataSet, and binding the DataSet to the GridView. It also shows calling a stored procedure and populating a DataTable from the returned DataAdapter.
{ // Define the ADO.NET objects. string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString; string selectSQL = "SELECT ProductID, ProductName, UnitPrice FROM Products"; SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(selectSQL,con); SqlDataAdapter adapter = new SqlDataAdapter(cmd); // Fill the DataSet. DataSet ds = new DataSet(); adapter.Fill(ds, "Products"); // Perform the binding. GridView1.DataSource = ds; GridView1.DataBind(); }
DataTable dtDetalle01 = new DataTable();
string ConnectionString = WebConfigurationManager.ConnectionStrings["cnnsenarit"].ConnectionString; using (SqlConnection con = new SqlConnection(ConnectionString)) { //Create the SqlCommand object SqlCommand cmd = new SqlCommand("EmisionCC.PR_CertificadoCCDatosCompletos", con); //Specify that the SqlCommand is a stored procedure cmd.CommandType = System.Data.CommandType.StoredProcedure;