M
Microsoft
Hi everyone,
Before I begin I should point out that I am quite new to programming and
VB.net and am using VS2003 with SQLExpress 2005.
I have two data tables a staff table and an office table, the linking field
is office_id. I have created a form and added a datagrid, when the form
loads I create a new DataAdapter, Connection and DataSet and select the
records from the staff table linking with the office table to display the
office name rather than the ID.
Private Sub frmStaff_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dcConn as New OleDB.OleDbConnection("Integrated Security=SSPI;Packet
Size=4096;Data Source='SERVER\INSTANCE';Initial Catalog=Planner;Persist
Security Info=False;Provider="SQLOLEDB.1")
Dim daStaff = New OleDb.OleDbDataAdapter("SELECT a.staff_id,
a.staff_initials, a.staff_name, a.staff_title, a.staff_active, b.office_name
FROM tblStaff a, tblOffice b WHERE a.staff_office_id = b.office_id", dcConn)
Dim dsStaff as New System.Data.DataSet
daStaff.Fill(dsStaff, "tblStaff")
' set the bding context
currManager = CType(Me.BindingContext(dsStaff.Tables("Staff")),
CurrencyManager)
' Set the databindings
DataGrid1.DataSource = dsStaff.Tables("Staff")
....
Here I create all the DataGridTextBoxColumn and set the mapping to the
relevant field, etc.
....
End Sub
' The procedure for saving the changes is:-
Private Sub SaveChanges()
Dim cmdBuilder As New OleDb.OleDbCommandBuilder(daStaff)
Dim lngRetVal As Long
lngRetVal = daStaff.Update(dsStaff, "Staff")
If lngRetVal > 0 Then
dsStaff.AcceptChanges()
End If
End Sub
The form loads ok and the grid is populated, however when I call the update
command on the DataAdapter I get an error saying that I cannot use the
commandbuilder to update multiple tables. So my question is how the hell do
I do this? I prefer to manually code it rather than using the wizards to
really understand it. Plus the wizards don't actually work SQLExpress 2005.
I have read several tutorials but none seem to cover what I want, my MCSD
book I bought doesn't really explain how to do this in real terms.
Any help, pointers, guidance or links to useful articles would be very much
appreciated. I'm completely lost and don'tknow where to go from here.
Thank you in advance for taking the time to read my query!
Cheers
Lee
Before I begin I should point out that I am quite new to programming and
VB.net and am using VS2003 with SQLExpress 2005.
I have two data tables a staff table and an office table, the linking field
is office_id. I have created a form and added a datagrid, when the form
loads I create a new DataAdapter, Connection and DataSet and select the
records from the staff table linking with the office table to display the
office name rather than the ID.
Private Sub frmStaff_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dcConn as New OleDB.OleDbConnection("Integrated Security=SSPI;Packet
Size=4096;Data Source='SERVER\INSTANCE';Initial Catalog=Planner;Persist
Security Info=False;Provider="SQLOLEDB.1")
Dim daStaff = New OleDb.OleDbDataAdapter("SELECT a.staff_id,
a.staff_initials, a.staff_name, a.staff_title, a.staff_active, b.office_name
FROM tblStaff a, tblOffice b WHERE a.staff_office_id = b.office_id", dcConn)
Dim dsStaff as New System.Data.DataSet
daStaff.Fill(dsStaff, "tblStaff")
' set the bding context
currManager = CType(Me.BindingContext(dsStaff.Tables("Staff")),
CurrencyManager)
' Set the databindings
DataGrid1.DataSource = dsStaff.Tables("Staff")
....
Here I create all the DataGridTextBoxColumn and set the mapping to the
relevant field, etc.
....
End Sub
' The procedure for saving the changes is:-
Private Sub SaveChanges()
Dim cmdBuilder As New OleDb.OleDbCommandBuilder(daStaff)
Dim lngRetVal As Long
lngRetVal = daStaff.Update(dsStaff, "Staff")
If lngRetVal > 0 Then
dsStaff.AcceptChanges()
End If
End Sub
The form loads ok and the grid is populated, however when I call the update
command on the DataAdapter I get an error saying that I cannot use the
commandbuilder to update multiple tables. So my question is how the hell do
I do this? I prefer to manually code it rather than using the wizards to
really understand it. Plus the wizards don't actually work SQLExpress 2005.
I have read several tutorials but none seem to cover what I want, my MCSD
book I bought doesn't really explain how to do this in real terms.
Any help, pointers, guidance or links to useful articles would be very much
appreciated. I'm completely lost and don'tknow where to go from here.
Thank you in advance for taking the time to read my query!
Cheers
Lee