473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Adding rows to a data table: Rows do not show up

Hello:

I defined a datatable with two columns:

dtTable = New DataTable("Names")

' Add three column objects to the table.
idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "AER Number"
idColumn.MaxLength = 20
dtTable.Columns.Add(idColumn)

idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "Case Version"
idColumn.MaxLength = 3
dtTable.Columns.Add(idColumn)

I am trying to insert rows into the table:

Dim row As DataRow

row = dtTable.NewRow()
row.BeginEdit()
row("AER Number") = "123"
row("Case Version") = "V3"

row.AcceptChanges

The last tow raises an error, "Cannot perform this operation on a row not in
the table."

And if I do not have this line, the row count remains at 0.

What am I doing wrong?

Venki

Oct 9 '06 #1
2 9188
Venki,

You need to add the row to the datatable:

Dim row As DataRow

row = dtTable.NewRow()

row.BeginEdit()
row("AER Number") = "123"
row("Case Version") = "V3"
row.EndEdit()

dtTable.Rows.Add(row)

dtTable.AcceptChanges()

Kerry Moorman
"vvenk" wrote:
Hello:

I defined a datatable with two columns:

dtTable = New DataTable("Names")

' Add three column objects to the table.
idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "AER Number"
idColumn.MaxLength = 20
dtTable.Columns.Add(idColumn)

idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "Case Version"
idColumn.MaxLength = 3
dtTable.Columns.Add(idColumn)

I am trying to insert rows into the table:

Dim row As DataRow

row = dtTable.NewRow()
row.BeginEdit()
row("AER Number") = "123"
row("Case Version") = "V3"

row.AcceptChanges

The last tow raises an error, "Cannot perform this operation on a row not in
the table."

And if I do not have this line, the row count remains at 0.

What am I doing wrong?

Venki
Oct 9 '06 #2
Kerry:

Thanks. I realized my mistake.

"Kerry Moorman" wrote:
Venki,

You need to add the row to the datatable:

Dim row As DataRow

row = dtTable.NewRow()

row.BeginEdit()
row("AER Number") = "123"
row("Case Version") = "V3"
row.EndEdit()

dtTable.Rows.Add(row)

dtTable.AcceptChanges()

Kerry Moorman
"vvenk" wrote:
Hello:

I defined a datatable with two columns:

dtTable = New DataTable("Names")

' Add three column objects to the table.
idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "AER Number"
idColumn.MaxLength = 20
dtTable.Columns.Add(idColumn)

idColumn = New DataColumn()
idColumn.DataType = System.Type.GetType("System.String")
idColumn.ColumnName = "Case Version"
idColumn.MaxLength = 3
dtTable.Columns.Add(idColumn)

I am trying to insert rows into the table:

Dim row As DataRow

row = dtTable.NewRow()
row.BeginEdit()
row("AER Number") = "123"
row("Case Version") = "V3"

row.AcceptChanges

The last tow raises an error, "Cannot perform this operation on a row not in
the table."

And if I do not have this line, the row count remains at 0.

What am I doing wrong?

Venki
Oct 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
31
by: One Handed Man \( OHM - Terry Burns \) | last post by:
My Brain is dead !!!!! I modify a single row in a DataTable By setting the FirstName column in a specific row to another name. ( Without Accepting Changes ). However, this statement still...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.