J
JamesB
Im just converting an app to .net (using VB) and I decided to use ado.net
also, rather than sticking with plain ado.
I have got my queries running fine with datareaders, but I'm having a little
trouble inserting records. I dont really want to use an SQL command as
single quotes in strings often cause headaches, so I have the code below.
I get an exception of "Object reference not set to an instance of an object"
at the line marked with * and checking my debug, workTable is still
"nothing".
Any clues or am I completely off track here!
Thanks
James.
Dim MyDataSet As New DataSet
Dim Adapter As New SqlDataAdapter
Adapter.SelectCommand = New SqlCommand("SELECT * FROM msg", DBConn)
Adapter.Fill(MyDataSet)
Dim workTable As New DataTable
workTable = MyDataSet.Tables.Item("msg")
* Dim workRow As DataRow = workTable.NewRow
workRow("msg_client") = client
workRow("msg_username") = username
workRow("msg_message") = Message
workRow("msg_recipient") = CStr(Recipient)
workRow("msg_submittime") = Now()
workRow("msg_status") = 0
workTable.Rows.Add(workRow)
Adapter.Update(MyDataSet)
also, rather than sticking with plain ado.
I have got my queries running fine with datareaders, but I'm having a little
trouble inserting records. I dont really want to use an SQL command as
single quotes in strings often cause headaches, so I have the code below.
I get an exception of "Object reference not set to an instance of an object"
at the line marked with * and checking my debug, workTable is still
"nothing".
Any clues or am I completely off track here!
Thanks
James.
Dim MyDataSet As New DataSet
Dim Adapter As New SqlDataAdapter
Adapter.SelectCommand = New SqlCommand("SELECT * FROM msg", DBConn)
Adapter.Fill(MyDataSet)
Dim workTable As New DataTable
workTable = MyDataSet.Tables.Item("msg")
* Dim workRow As DataRow = workTable.NewRow
workRow("msg_client") = client
workRow("msg_username") = username
workRow("msg_message") = Message
workRow("msg_recipient") = CStr(Recipient)
workRow("msg_submittime") = Now()
workRow("msg_status") = 0
workTable.Rows.Add(workRow)
Adapter.Update(MyDataSet)