Click to See Complete Forum and Search --> : Help... Error when trying to fill a DataSet.


Tengan
May 28th, 2001, 07:43 AM
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();
}

saurabhN
June 8th, 2001, 08:35 PM
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
mailsaurabhn@webveda.com
http://Learncsharp.cjb.net