How to add new row to typed dataset

S

SH

How do I add a new DataRow to a typed DataSet?

I would expect the following code to work:

Dim drCustomer As NorthwindDataSet.CustomerRow
drCustomer = NorthwindDataSet.CustomersDataTable.NewCustomersRow
drCustomer.CompanyName = "xxx"

But the NewCustomersRow method is not valid. It doesn't even come up in
IntelliSense.

The database is in SqlServerCe (for PDAs), but that shouldn't make a
difference.

Thanks for any assistance.
 
W

W.G. Ryan - MVP

DataSet1 ds = new DataSet1();

DataSet1.DataTable1Row = ds.DataTable1.NewDataTable1Row();

--This syntax is working with mine. You may need to save the dataset again,
but it should be working.
 
S

SH

The syntax doesn't work for me.

I still don't get NewDataTable1Row as a method. All I get are Equals,
GetDataTableSchema, GetTypedDataSchema and ReferenceEquals as valid
methods for the table.

Is there something I'm missing in the table definition?
 
W

W.G. Ryan - MVP

I'm assuing you already have a acolumn in it right? I just added a dataSet,
added a dataTable, added a column and used it like that. That's the exact
syntax and it compiled and ran. You may want to look in the vb or cs file
that is the dataset and see if something is missing.
 
A

AMDRIT

Try running the custom tool on the dataset from the context menu. The
generated code may not have been regenerated.
 
B

Bart Mermuys

Hi,

SH said:
How do I add a new DataRow to a typed DataSet?

I would expect the following code to work:

Dim drCustomer As NorthwindDataSet.CustomerRow
drCustomer = NorthwindDataSet.CustomersDataTable.NewCustomersRow
drCustomer.CompanyName = "xxx"

NorthwindDataSet.CustomersDataTable is an inner class, you need an instance.
If there is a NorthwindDataSet on the form with the same name, then
NorthwindDataSet can be both a class and instance, depending on how you
further qualify it (VB.NET). In this case the instance you need is
NorthwindDataSet.Customers (without the DataTable part).

Dim drCustomer As NorthwindDataSet.CustomerRow
drCustomer = NorthwindDataSet.Customers.NewCustomersRow()
drCustomer.CompanyName = "xxx"

If there is no NorthwindDataSet on the Form, then you need to what W.G. Ryan
suggested, create an instance first:

Dim dsNorthwind As New NorthwindDataSet()
Dim drCustomer As NorthwindDataSet.CustomerRow
drCustomer = dsNorthwind.Customers.NewCustomersRow()
drCustomer.CompanyName = "xxx"

HTH,
Greetings
 
S

SH

OK. Thanks guys. Your assistance got me poking around in the right
places and I found what my problem was - my TableAdapter was not set up
correctly.

Thanks. Without your help I would have spent much longer on this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top