S
sparkle
Hi,
I'm having a problem getting data into my db using datatable and
commandbuilder.
The 'cars' table in my sql server holds: employeeID, carID, make,
model, year.
I have a datagrid with car info in it. The grid is bound to a
datatable called dtAutos. The grid includes make, model, year. The
grid updates, adds a new row just fine into the db, but without the
employeeID and/or CarID info. If I manually put an employeeID or
CarID into the table, the row will appear.
I have textboxes with the employeeID and CarID data. They are bound to
a datatable called dtAssignments.
When I add a new car to the datagrid and click the update button, I
want the new row to have the employeeID from the textbox inserted
into the db along with the make, model and year.
Here is how I'm attempting to do this:
Sub GetCommands()
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim CurrentRow As DataRow
Dim iPos As Integer
dtAutos = dsAutos.Tables("cars")
CurrentRow = dtAutos.Rows(iPos)
CurrentRow("carid") = txtCarID.Text
CurrentRow.AcceptChanges()
Try
GetCommands()
da.Update(dtAutos)
Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
grdAutos.Refresh()
End Sub
Can anybody help? If you need clarification, post back, I'm very
confused as to why I can't read info straight from a textbox into a
db...
I'm having a problem getting data into my db using datatable and
commandbuilder.
The 'cars' table in my sql server holds: employeeID, carID, make,
model, year.
I have a datagrid with car info in it. The grid is bound to a
datatable called dtAutos. The grid includes make, model, year. The
grid updates, adds a new row just fine into the db, but without the
employeeID and/or CarID info. If I manually put an employeeID or
CarID into the table, the row will appear.
I have textboxes with the employeeID and CarID data. They are bound to
a datatable called dtAssignments.
When I add a new car to the datagrid and click the update button, I
want the new row to have the employeeID from the textbox inserted
into the db along with the make, model and year.
Here is how I'm attempting to do this:
Sub GetCommands()
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim CurrentRow As DataRow
Dim iPos As Integer
dtAutos = dsAutos.Tables("cars")
CurrentRow = dtAutos.Rows(iPos)
CurrentRow("carid") = txtCarID.Text
CurrentRow.AcceptChanges()
Try
GetCommands()
da.Update(dtAutos)
Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
grdAutos.Refresh()
End Sub
Can anybody help? If you need clarification, post back, I'm very
confused as to why I can't read info straight from a textbox into a
db...