Re: Multiple table in dataset query
- From: "Microsoft" <lee.clements.nospam@xxxxxxxxxxxxxxx>
- Date: Thu, 1 Feb 2007 12:55:23 -0000
Yes I think I undestand where your coming from, effectively I need to create
a new parameterized query for the update and insert command which is then
assigned to the dataadapter.
I have found some articles on doing this so I will have a play around with
it. The other problem I've recognised in doing this is that ideally I need a
combobox in the dataqgrid for the user to select from the fields in the
other table - which isn't supported with the datagrid in 1.1, not sure about
2.0. I will get to this later, for now I will concentrate on getting the
updates working.
Thanks for your help.
Lee
"RobinS" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:DIednU8aQKZ3h1zYnZ2dnUVZ_r-onZ2d@xxxxxxxxxxxxxx
First of all, be aware that the CommandBuilder is only effective for
really simple updates, like if you have a list of fields with a primary
key.
You can *not* do updates using the CommandBuilder if you have a join in
your SQL statement.
You will have to write your own SQL for the update, insert, and delete
commands, so they update only the one table.
Example:
Update tblStaff Set staff_id = ?, staff_initials = ?, staff_name = ?,
staff_title = ?, staff_active = ? WHERE staff_id = ?
and then add parameters for those (in that order) from the data row in
your dataset.
Does that make sense?
Robin S.
-------------------------------------
"Microsoft" <lee.clements.nospam@xxxxxxxxxxxxxxx> wrote in message
news:%2380X%23$VRHHA.4448@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- Re: Multiple table in dataset query
- From: Kerry Moorman
- Re: Multiple table in dataset query
- References:
- Re: Multiple table in dataset query
- From: RobinS
- Re: Multiple table in dataset query
- Prev by Date: Re: Constraint error on fill of dataset
- Next by Date: Re: Stored Proc results in DataGridView
- Previous by thread: Re: Multiple table in dataset query
- Next by thread: Re: Multiple table in dataset query
- Index(es):
Relevant Pages
|