V
vbDavidC
I am adding a new record to a table via a dataset/adapter.
I have got the following to work for me but I am wondering if there is
a better way to do this.
I am having to have something in my DS before I can add records, since
DS does not exist. I'd rather not have a SELECT since I really don't
need any records in my dataset that I will be adding a new record to.
Dim dsNewRow As DataRow
Dim DS As New DataSet
Dim DA As New OleDb.OleDbDataAdapter
con.Open()
'part I have a question about
sql = "SELECT * FROM lookupTable WHERE Lname = ''"
DA = New OleDb.OleDbDataAdapter(sql, con)
DA.Fill(DS, "lookupTable")
'end
dsNewRow = DS.Tables("lookupTable").NewRow()
dsNewRow.Item(1) = "test string"
DS.Tables("lookupTable").Rows.Add(dsNewRow)
DA.Fill(DS, "lookupTable")
In my SQL command I have also used something like "SELECT * FROM
lookupTable WHERE LName = ''.
I am new to VB.net and want to make sure I learn the right method.
I have got the following to work for me but I am wondering if there is
a better way to do this.
I am having to have something in my DS before I can add records, since
DS does not exist. I'd rather not have a SELECT since I really don't
need any records in my dataset that I will be adding a new record to.
Dim dsNewRow As DataRow
Dim DS As New DataSet
Dim DA As New OleDb.OleDbDataAdapter
con.Open()
'part I have a question about
sql = "SELECT * FROM lookupTable WHERE Lname = ''"
DA = New OleDb.OleDbDataAdapter(sql, con)
DA.Fill(DS, "lookupTable")
'end
dsNewRow = DS.Tables("lookupTable").NewRow()
dsNewRow.Item(1) = "test string"
DS.Tables("lookupTable").Rows.Add(dsNewRow)
DA.Fill(DS, "lookupTable")
In my SQL command I have also used something like "SELECT * FROM
lookupTable WHERE LName = ''.
I am new to VB.net and want to make sure I learn the right method.