Fill DataSet Schema

Topics: Data Access Application Block
May 19, 2008 at 8:12 AM
Hi

I want to Fill the DataSet with a schema

can ExecuteDataSet do this for me

If I solve this problem with ADO.NET so I need more objects and more code to be written

Thanks in advance

Mohamed
May 19, 2008 at 2:20 PM

Hi Mohamed,

Is this what you're looking for? 

    1 using System;

    2 using System.Data;

    3 using Microsoft.Practices.EnterpriseLibrary.Data;

    4 

    5 namespace DAABTypeDatasetRepro

    6 {

    7     class Program

    8     {

    9         static void Main(string[] args)

   10         {

   11             Database db

   12                 = DatabaseFactory.CreateDatabase("DAABTypeDatasetRepro.Properties.Settings.NorthwindConnectionString");

   13 

   14             NorthwindDataSet ds = new NorthwindDataSet();

   15             db.LoadDataSet(CommandType.Text, "select * from Customers", ds, new string[] { "Customers" });

   16 

   17             foreach (var item in ds.Customers)

   18             {

   19                 Console.WriteLine("Name: {0}", item.ContactName);

   20             }

   21 

   22         }

   23     }

   24 }

Fernando

AboOmar wrote:
Hi

I want to Fill the DataSet with a schema

can ExecuteDataSet do this for me

If I solve this problem with ADO.NET so I need more objects and more code to be written

Thanks in advance

Mohamed


May 20, 2008 at 6:30 AM

Hi fsimonazzi

Great thanks for your reply

But I work with Untyped DataSet

But I work around the issue and do the following code :

public

static void GetSchema(ref DataSet dataSet, string commandText)

 

{


            DbCommand cCommand = db.GetSqlStringCommand(commandText);
            DbDataAdapter daAdapter = db.GetDataAdapter();

 

            cCommand.Connection = db.CreateConnection();

            daAdapter.SelectCommand = cCommand;

            daAdapter.FillSchema(dataSet,

SchemaType.Source);

 

            cCommand.Dispose();

             daAdapter.Dispose();

}

But I have a question :

I were thinking that the function GetDataAdapter() returns an adapter that carries inside it the select command that is performed when calling ExecuteDataSet() before
But I get an DbDataAdapter instance uninitialized so, what this function exactly does ?

and I have a suggestion:

It will be very flexible and nice if the ExecuteDataSet has a parameter that allow if I can generate the DataSet with its schema or not .

Thanks again for reply

Mohamed