Cannot add new row to DataSet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm populating a DataSet using a stored procedure.When I have at least one
record returned I can add a new row to the DataSet, but if I don't get any
records and I try to add a new row I get "No table defined", or something
like that.
How can I get the table created with the necessary columns that would be
returned from the stored proc. even when I don't get any data returned.
Is there a way to get the table schema from the stored proc. I'm using
Sybase ASE 12.5.

Thanks Much,
Dan
 
Well, this is what I do:
.....execute the command to get data using stored proc.
da.Fill(ds, "MyTableName");

Remember, I can add rows to the table only if the SP returns at least one
row of data, otherwise I cannot.
Why would the table be created only when we have data returned from
database, and not otherwise.
Remember, if I check the dataSet and the dataTable they the table does not
exist.
I would like to know why, and how can I force the dataTable to be created.

Regards,
Dan
 
If you dont specify how a dataset should look (what tables it should
have, what columns and types of data in that columns), how the program
is to guess all that information when you insert a new row?
When you first get some rows from database, the DataAdapter.Fill method
is smart enough, so when it does not know anything about your dataset
schema, it asks database about it and creates a schema first. Then it
fills the dataset with data. When it has no data to fill, it seems to
skip the schema creation.
Filling dataset this way is very slow and may cause errors.
You may:
1. Create a typed dataset (Project -> Add new item -> Dataset). First
create an xsd file (by dropping tables or stored procedures from Server
Explorer) and then Visual Studio (I guess you use VS) will create a
typed dataset automatically for you
2. Create an untyped dataset (just like you've done before) and then
manually set columns and data types (Dataset -> Table -> Properties ->
Columns Collection)
 
Thanks for your reply,
I want to do everything in code, so dragging and dropping is not an option
here. Is there a way to get the schema without manually specifying the
columns. How does the dataAdapter get the schema? Can you get schema from a
stored procedure, even if no data is returned.

Regards,
Dan
 
The answer is very simple. Your stored procedure is not executing select
statement based on some precondition. Say, if no records found in master
table ; or the select statement gets executed only if one of the passed
parameter is not null or Zero.

Please recheck the stored proc flow. This will surely solve the problem. Try
to ensure your SQL select statement gets executed for any parameter supplied.

All the Best !
 
Back
Top