NewRow not working on DataTable...

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Okay,

I have an application that I need to create a local DataTable bound to a DataGrid so the user can create their list of parts prior to inserting them into the database.

I had been using a simple CheckBoxList, but the formatting limitations were really ticking me off (extraneous spaces removed automatically), so I decided to switch to a bound DataGrid.

Here is the code I have for when the user clicks the "Add" button:

Code:
 Dim NewTableRow As System.Data.DataRow = dsSelectedParts.Tables("dtSelectedParts").NewRow()
 
 If Len(Trim(txtPartNum.Text)) > 0 Then
   PartNumber = UCase(txtPartNum.Text)
   GoodPart = ValidPart(PartNumber)
 Else
   GoodPart = False
 End If
 
 If GoodPart Then
   NewTableRow("RowID") = PartIndex
   NewTableRow("PartNumber") = Session("PartNum")
   NewTableRow("PartDesc") = Session("PartDesc")
   NewTableRow("PartMBS") = Session("PartMBS")
   NewTableRow("PartRev") = Session("PartRev")
   NewTableRow("PartDwg") = Session("PartDwg")
 
   dsSelectedParts.Tables("dtSelectedParts").Rows.Add(NewTableRow)
   Dim RowCount As Integer = dsSelectedParts.Tables("dtSelectedParts").Rows.Count.ToString()
   Session("TempVar") = dsSelectedParts.Tables("dtSelectedParts").Rows(PartIndex).Item("PartDesc").ToString
   dgSelectedParts.DataBind()

I have the code stop on the assignment of Session("TempVar"), and the first time, the PartIndex value is 0, and the Row.Count propery of the table is 1. The second time, the PartIndex value is 1, but the Rows.Count property is STILL 1.

What am I missing here? This seems SO SIMPLE!!!!

Kahuna
 
Back
Top