0% found this document useful (0 votes)
103 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.

Uploaded by

Victor Galarza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 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.

Uploaded by

Victor Galarza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

ADO.

NET C# DataAdapter

<asp:GridView ID="GridView1" runat="server" />

protected void Page_Load(object sender, EventArgs e)


{
// 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;

//Add the input parameters to the command object


cmd.Parameters.AddWithValue("@Tramite", 12344);
cmd.Parameters.AddWithValue("@GrupoB", 3);
cmd.Parameters.AddWithValue("@TipoForm", 6);
cmd.Parameters.AddWithValue("@NoFormCalculo", 27);
cmd.Parameters.AddWithValue("@Mensaje", "hola");

SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);


DataSet ds = new DataSet();
adapter1.Fill(ds, "CertificadoCC");
//dtDetalle01 = ds.Tables[0];
dtDetalle01 = ds.Tables["CertificadoCC"];
}

You might also like