Adding rows to dataset (a.k.a. can an MVP help me please!)

  • Thread starter Thread starter Rick Palmer
  • Start date Start date
R

Rick Palmer

I'm totally lost here....

I have a blank typed dataset designed to hold invoice data, OK? The
dataset has two tables, InvoiceHeaders and InvoiceLines. The invoice data
is generated by a system/36 emulator and therefore comes in as a
comma-delimited text file. My task is to get the text into the dataset so I
can bind it to a crystal report and print the invoices. SO:

I open the header text file, and go into this loop to attempt to fill the
header table:

Dim Ivc as New IvcDataSet
Do While Not EOF(1)
Dim x As IvcDataSet.InvHeadersRow
Input(1, x.InsuredNo)
Input(1, x.Item("EntryMonth"))
Input(1, x.Item("KeyerInit"))....
Ivc.Tables("InvHeaders").Rows.Add(x)
x = Nothing
Loop

When I run the code, I get an error on the first input line because x is not
set to an instance of an object. Being familiar with this type error I
change the Dim line to read:

Dim x As New IvcDataSet.InvHeadersRow

Now, I have a blue squigly under the x that says "Argument not specified for
parameter 'rb'..." or something like that. I find out that the rb is a
System.Data.DataRowBuilder object. So I turn to the MSDN library to find
out about the DataRowBuilder class. My research reveals that, according to
MSDN, "This type supports the .NET Framework infrastructure and is not
intended to be used directly from your code." So how the hell am I supposed
to add rows to my datasets????
 
Hi Rick,

The fact is that you can't create a DataRow using its constructor. You must
call the NewRow() method on the table for which you want to create a row.
This ensures that the created row has the right schema.

So you should modify your code to read like this:

Dim Ivc as New IvcDataSet
Do While Not EOF(1)
Dim x As IvcDataSet.InvHeadersRow = IvcDataSet.InvHeaders.NewRow()
Input(1, x.InsuredNo)
Input(1, x.Item("EntryMonth"))
Input(1, x.Item("KeyerInit"))....
Ivc.Tables("InvHeaders").Rows.Add(x)
x = Nothing
Loop

Good luck,
Arnaud
 
That got it! Thanks!


AW said:
Hi Rick,

The fact is that you can't create a DataRow using its constructor. You must
call the NewRow() method on the table for which you want to create a row.
This ensures that the created row has the right schema.

So you should modify your code to read like this:

Dim Ivc as New IvcDataSet
Do While Not EOF(1)
Dim x As IvcDataSet.InvHeadersRow = IvcDataSet.InvHeaders.NewRow()
Input(1, x.InsuredNo)
Input(1, x.Item("EntryMonth"))
Input(1, x.Item("KeyerInit"))....
Ivc.Tables("InvHeaders").Rows.Add(x)
x = Nothing
Loop

Good luck,
Arnaud
 
Back
Top