|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding rows to a data table: Rows do not show upI 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 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 Show quoteHide quote "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 > Kerry:
Thanks. I realized my mistake. Show quoteHide quote "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 > >
Locating Windows Application Installation Keys
Something I don't quite understand about "file in use by another process" exceptions..... Reflection - Delay Signing Error - HELP Bad practice with Enumerations.... How to find my information Merge VB.NET and C# MDI Child start position &H201 MaskedTextBox Help Round to 2 decimals in a Datalist |
|||||||||||||||||||||||