G
Guest
Whenever I run this code, I get a row added to my table in the primary field
whose text is "System.Object". This code is intended to simply add a single
row to a single table. Anybody see why this is happening and what I need to
do to stop the extra row?
Private Sub btnDeleteOrder_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDeleteOrder.Click
Dim vbResponse As Integer
vbResponse = MessageBox.Show("Are you sure that you want to delete "
+ tbOrd.Text + "?", "Confirm Delete", MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning)
If vbResponse = 1 Then
Dim strSQL As String
Dim strDel As String
strDel = tbOrd.Text.ToString()
strSQL = "SELECT * FROM Orders WHERE Order = @Order"
Dim da As New SqlDataAdapter(strSQL, cn)
da.SelectCommand.Parameters.AddWithValue("@Order", strDel)
Dim tbl As New DataTable("Orders")
tbl.Columns.Add("Order", GetType(String))
tbl.Columns.Add("UOM", GetType(String))
da.Fill(tbl)
Dim rowToDelete As DataRow
rowToDelete = tbl.Rows(0)
rowToDelete.Delete()
Try
da.Update(tbl)
MessageBox.Show("Order Deleted", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
Console.WriteLine("Call to SqlDataAdapter.Update " & _
"threw exception: {0}", ex.Message)
End Try
End If
End Sub
Thanks,
Ken
whose text is "System.Object". This code is intended to simply add a single
row to a single table. Anybody see why this is happening and what I need to
do to stop the extra row?
Private Sub btnDeleteOrder_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDeleteOrder.Click
Dim vbResponse As Integer
vbResponse = MessageBox.Show("Are you sure that you want to delete "
+ tbOrd.Text + "?", "Confirm Delete", MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning)
If vbResponse = 1 Then
Dim strSQL As String
Dim strDel As String
strDel = tbOrd.Text.ToString()
strSQL = "SELECT * FROM Orders WHERE Order = @Order"
Dim da As New SqlDataAdapter(strSQL, cn)
da.SelectCommand.Parameters.AddWithValue("@Order", strDel)
Dim tbl As New DataTable("Orders")
tbl.Columns.Add("Order", GetType(String))
tbl.Columns.Add("UOM", GetType(String))
da.Fill(tbl)
Dim rowToDelete As DataRow
rowToDelete = tbl.Rows(0)
rowToDelete.Delete()
Try
da.Update(tbl)
MessageBox.Show("Order Deleted", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
Console.WriteLine("Call to SqlDataAdapter.Update " & _
"threw exception: {0}", ex.Message)
End Try
End If
End Sub
Thanks,
Ken