+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Using the DbCommandSetDataProvider With Stored Procedures

net
(combit Team) #1
Valid from List & Label 23
Use the DbCommandSetDataProvider in order to enable stored procedures as data sources. Pass your Command instances to it, and set the CommandType property to CommandType.StoredProcedure in each case. The exact procedure is shown below using a small C# example that uses the well-known Northwind database on a Microsoft SQL Server:
...
using (ListLabel LL = new ListLabel())
{
    // Configure connection to SQL Server
    SqlConnectionStringBuilder sqlConnectionParameters = new SqlConnectionStringBuilder();
    sqlConnectionParameters.DataSource = "<Your MS SQL Server Instance Name>";
    sqlConnectionParameters.InitialCatalog = "Northwind";
    sqlConnectionParameters.IntegratedSecurity = true;
    SqlConnection sqlConnection = new SqlConnection(sqlConnectionParameters.ToString());

    // Configure SqlCommand for stored procedure
    SqlCommand sqlStoredProcedureCommand = new SqlCommand("[dbo].[CustOrderHist]", sqlConnection);
    sqlStoredProcedureCommand.CommandType = CommandType.StoredProcedure;
    sqlStoredProcedureCommand.Parameters.AddWithValue("@CustomerID", "ALFKI");

    // Configure data provider
    DbCommandSetDataProvider dataProvider = new DbCommandSetDataProvider();
    dataProvider.AddCommand(sqlStoredProcedureCommand, "CustOrderHist");
    LL.DataSource = dataProvider;

    // Call designer
    LL.Design();
}
...
IDKBTE001343 KBTE001343