LoadDataRow

klover

New member
Joined
Nov 20, 2006
Messages
4
Programming Experience
1-3
Hello vb .net gurus

i'm trying to place a new data row at the bottom of the datagrid. i took this source code from an existing program that works fine but on the new program i doesn't do same as the existing program. could anyone help me out to see where the problem is occurring i have no idea.:p thanks

VB.NET:
Private Sub cmd_saveelement_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_saveelement.Click
Dim newrow As DataRow
elementdt(0) = ref_frm_newdata.dg_inputelement.VisibleRowCount
elementdt(1) = ref_frm_newdata.txt_customer.Text
elementdt(2) = ref_frm_newdata.txt_processno.Text
elementdt(3) = cb_elementname.SelectedValue
elementdt(4) = cb_materialcode.SelectedValue
If txt_gage.Text <> "" Then
elementdt(5) = CType(txt_gage.Text, System.Int32)
Else
elementdt(5) = 0.0
End If
If txt_ply.Text <> "" Then
elementdt(6) = CType(txt_ply.Text, System.Int32)
Else
elementdt(6) = 0
End If
If txt_pit.Text <> "" Then
elementdt(7) = CType(txt_pit.Text, System.Int32)
Else
elementdt(7) = 0
End If
If txt_wid.Text <> "" Then
elementdt(8) = CType(txt_wid.Text, System.Int32)
Else
elementdt(8) = 0
End If
elementdt(9) = 0.0
elementdt(10) = 0.0
ref_frm_newdata.ds_element1.Element.BeginLoadData()
newrow = ref_frm_newdata.ds_element1.Element.LoadDataRow(elementdt, False)
ref_frm_newdata.ds_element1.Element.EndLoadData()
ClearTextbox()
InitializeDataset()
End Sub

* i noticed at the "newrow = ref_frm_newdata.ds_element1.Element.LoadDataRow(elementdt, False)" line the row state is modified how to you change this to added?
 
Last edited:
Load Data Row works in "upsert" fashion. If the datatable determines that the row already exists, then new values are copied off the provided row to modify the existing row -i.e. an UPDATE. If the row doesnt exist, the row is INSERTed. This distinction is made clear in the intellisense tooltip that appears for LoadDataRow

you have a row of:

id, name
1, fred

Load it the first time. Table contains:

id, name
1, fred (datarowstate.added)


Change fred to joe in the row and load it again. Table contains:
1, joe (datarowstate.modified)


----
I suggest that you use AddRow() or Add<Typed Row Name>Row() passing in the row you wish to add. I do it like this, for example:

VB.NET:
Dim ro as MyDataSet.PersonDataRow
ro = MyDataSetInstance.PersonDataTable.NewPersonRow()
ro.id = 1
ro.name  = "fred"
MyDataSetInstance.PersonDataTable.AddPersonRow(ro)
 
Back
Top