A
Alex
Whenever I run this code, I get an extra row added to my table with a
primary field text of "System.Object". This code is intended to
simply add a single row to a single table based on the value in the
tbOrd.text textbox. Instead, two rows are going in - one is intended,
the second is not. Anybody see why this is happening and what I need
to do to stop the extra row from being added.
Dim strNewOrder, strSQL As String
Dim rowToInsert As DataRow
Dim tbl As New DataTable("Orders")
tbl.Columns.Add("Order", GetType(String))
tbl.Columns.Add("ID", GetType(String))
strNewOrder = tbOrd.Text
strSQL = "INSERT INTO Orders " & _
" (Order) VALUES " & _
" (@Order)"
Dim da As New SqlDataAdapter(strSQL, cn)
da.SelectCommand.Parameters.AddWithValue("Order", strNewOrder)
da.Fill(tbl)
cn.Open()
rowToInsert = tbl.Rows.Add(New Object(), strNewOrder)
Dim cmdInsert As New SqlCommand(strSQL, cn)
cmdInsert.Parameters.AddWithValue("@Order",
rowToInsert("Order"))
Try
cmdInsert.ExecuteNonQuery()
rowToInsert.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cn.Close()
End Sub
Thanks
primary field text of "System.Object". This code is intended to
simply add a single row to a single table based on the value in the
tbOrd.text textbox. Instead, two rows are going in - one is intended,
the second is not. Anybody see why this is happening and what I need
to do to stop the extra row from being added.
Dim strNewOrder, strSQL As String
Dim rowToInsert As DataRow
Dim tbl As New DataTable("Orders")
tbl.Columns.Add("Order", GetType(String))
tbl.Columns.Add("ID", GetType(String))
strNewOrder = tbOrd.Text
strSQL = "INSERT INTO Orders " & _
" (Order) VALUES " & _
" (@Order)"
Dim da As New SqlDataAdapter(strSQL, cn)
da.SelectCommand.Parameters.AddWithValue("Order", strNewOrder)
da.Fill(tbl)
cn.Open()
rowToInsert = tbl.Rows.Add(New Object(), strNewOrder)
Dim cmdInsert As New SqlCommand(strSQL, cn)
cmdInsert.Parameters.AddWithValue("@Order",
rowToInsert("Order"))
Try
cmdInsert.ExecuteNonQuery()
rowToInsert.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cn.Close()
End Sub
Thanks