ado.net "add new"

  • Thread starter Thread starter Julian
  • Start date Start date
J

Julian

Hi
I am just trying to get to grips with ado.net .

I simply wish to add data from some text boxes back to a new row in the
dataset on clicking a save button.

How do you create the new row in the dataset make sure this row is selected
and read the data from the text boxes to the various columns in the data
set?

Many thanks

Julian
 
It's pretty straightforward and I thought it was in the
MSDN somewhere, but here's what you do:

Dim dRow as DataRow (or DataRow dRow in C#)

dRow = [DataTable].NewRow
(the name of the datatable variable goes in place of
[DataTable])

[DataTable].Rows.Add(dRow)
(This step can come before or after you set the values of
the columns)

dRow.item(i) = xxx 'Set the value of a column
(dRow = xxx in C#)

That's it.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"
 
That's pretty much it except for the order of adding the row to the table vs
settting the data. If the table has a primary key, which all good tables
should, you will need to at least set the value for this field before adding
the row to the table. I personally find it better practice to set any
fields you know in advance before adding the row to the table.

Rick

Jeff Levinson said:
It's pretty straightforward and I thought it was in the
MSDN somewhere, but here's what you do:

Dim dRow as DataRow (or DataRow dRow in C#)

dRow = [DataTable].NewRow
(the name of the datatable variable goes in place of
[DataTable])

[DataTable].Rows.Add(dRow)
(This step can come before or after you set the values of
the columns)

dRow.item(i) = xxx 'Set the value of a column
(dRow = xxx in C#)

That's it.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"

-----Original Message-----
Hi
I am just trying to get to grips with ado.net .

I simply wish to add data from some text boxes back to a new row in the
dataset on clicking a save button.

How do you create the new row in the dataset make sure this row is selected
and read the data from the text boxes to the various columns in the data
set?

Many thanks

Julian


.
 
Looks too easy!

Many thanks

Julian

Rick Ferguson said:
That's pretty much it except for the order of adding the row to the table vs
settting the data. If the table has a primary key, which all good tables
should, you will need to at least set the value for this field before adding
the row to the table. I personally find it better practice to set any
fields you know in advance before adding the row to the table.

Rick

Jeff Levinson said:
It's pretty straightforward and I thought it was in the
MSDN somewhere, but here's what you do:

Dim dRow as DataRow (or DataRow dRow in C#)

dRow = [DataTable].NewRow
(the name of the datatable variable goes in place of
[DataTable])

[DataTable].Rows.Add(dRow)
(This step can come before or after you set the values of
the columns)

dRow.item(i) = xxx 'Set the value of a column
(dRow = xxx in C#)

That's it.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"

-----Original Message-----
Hi
I am just trying to get to grips with ado.net .

I simply wish to add data from some text boxes back to a new row in the
dataset on clicking a save button.

How do you create the new row in the dataset make sure this row is selected
and read the data from the text boxes to the various columns in the data
set?

Many thanks

Julian


.

 
Back
Top