CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    Sweden
    Posts
    4

    Help... Error when trying to fill a DataSet.

    I get the following message when I try to fill a dataset with output from a stored procedure... "expected TableMappings['Table'] to exist." Debugging goes all the way down to sqlDSCommand.FillDataSet(dsInvoice);

    Below is the code snippet I run. I thought DataSets were filled automatically and that they use the mappings set in the stored procedure. What's wrong?

    Code notes - periodBegin and periodEnd are parameters where dates are stored. Added the second row (dsInvoice.Table.Add) recently but I still got the same error message.

    dsInvoice = new DataSet();
    dsInvoice.Tables.Add("InvoiceBasis");

    sqlDSCommand = new SQLDataSetCommand(spName, sqlConn);

    sqlDSCommand.SelectCommand.ActiveConnection.Open();

    try
    {
    sqlDSCommand.SelectCommand.Parameters.Add(new SQLParameter("@FromDate", SQLDataType.DateTime));
    sqlDSCommand.SelectCommand.Parameters["@FromDate"].Direction = ParameterDirection.Input;
    sqlDSCommand.SelectCommand.Parameters["@FromDate"].Value = periodBegin;

    sqlDSCommand.SelectCommand.Parameters.Add(new SQLParameter("@ToDate", SQLDataType.DateTime));
    sqlDSCommand.SelectCommand.Parameters["@ToDate"].Direction = ParameterDirection.Input;
    sqlDSCommand.SelectCommand.Parameters["@ToDate"].Value = periodEnd;

    sqlDSCommand.FillDataSet(dsInvoice);
    }
    finally
    {
    sqlDSCommand.SelectCommand.ActiveConnection.Close();
    }




  2. #2
    Join Date
    Dec 2000
    Location
    Bombay, India
    Posts
    50

    Re: Help... Error when trying to fill a DataSet.

    hi,
    In beta 1, datasets get filled automatically, but you have to specify the table name to the dataset while filling. This table name should corrospond to the table name in the database.
    Hence change this line ...

    sqlDSCommand.FillDataSet(dsInvoice,"TableName");

    change the "TableName", to whatever is the name of the table you are retriving ..


    Saurabh Nandu
    mail[email protected]
    http://Learncsharp.cjb.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured