I can't comment on other authors, but I've written a lot of code that
demonstrates or uses the CB and it just does not work that way. All you need
to do is register it with the DA. Once it's setup when Update fires, it
checks to see if there's a CB present. If there is, it generates the
commands (the first time) and then executes the generated code. I also
demonstrated what's being generated for debug purposes by using the "Get"
commands--but that's all they're needed for.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Scott M." <s-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That's good information to know but not documented in the materials I've
> read (MS Press & WROX titles). In those texts, they show the
commandbuilder
> using GetInsertCommand, GetUpdateCommand & GetDeleteCommand.
>
>
> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Huh? You don't have to call the CB to manually create any of the action
> > commands. Once you link the CB to the DA, it's done automatically behind
> the
> > scenes. See my article on the command builder FMI.
> > http://www.betav.com/msdn_magazine.htm
> >
> > --
> > ____________________________________
> > William (Bill) Vaughn
> > Author, Mentor, Consultant
> > Microsoft MVP
> > www.betav.com
> > Please reply only to the newsgroup so that others can benefit.
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > __________________________________
> >
> > "Scott M." <s-(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > You created the CommandBuilder objects but never generated the Update
> > > commands necessary:
> > >
> > > 'Create command builders which is necessary to update the database
> > > Dim SecCommandBuilder As OleDbCommandBuilder = New
> > > OleDbCommandBuilder _(SecDataAdapter)
> > >
> > > SeccommandBuilder.GetUpdateCommand()
> > >
> > > Dim HistCommandBuilder As OleDbCommandBuilder = New
> > > OleDbCommandBuilder _(HistDataAdapter)
> > >
> > > HistCommandBuilder.GetUpdateCommand
> > >
> > > "Chris Lee" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > I am using the following code below to update a simple Access
database
> > > > with historical stock prices:
> > > >
> > > > -------------------code
> > > > snippet----------------------------------------
> > > > 'Open connection to update data
> > > > Dim myConn As New OleDbConnection(ConnectString)
> > > > myConn.Open()
> > > >
> > > > 'Create the SQL queries
> > > > Dim SQLSecurity As String = "SELECT * FROM [Security]"
> > > > Dim SQLHistory As String = "SELECT * FROM [History]"
> > > >
> > > > 'Create new DataAdapter objects
> > > > Dim SecDataAdapter As New OleDbDataAdapter(SQLSecurity, myConn)
> > > > Dim HistDataAdapter As New OleDbDataAdapter(SQLHistory, myConn)
> > > >
> > > > 'Create new datasets
> > > > Dim SecDataSet As New DataSet()
> > > > Dim HistDataSet As New DataSet()
> > > >
> > > > 'Fill datasets to store existing data
> > > > SecDataAdapter.Fill(SecDataSet, "Security")
> > > > HistDataAdapter.Fill(HistDataSet, "History")
> > > >
> > > > 'Create command builders which is necessary to update the database
> > > > Dim SecCommandBuilder As OleDbCommandBuilder = New
> > > > OleDbCommandBuilder _(SecDataAdapter)
> > > > Dim HistCommandBuilder As OleDbCommandBuilder = New
> > > > OleDbCommandBuilder _(HistDataAdapter)
> > > >
> > > > For i = 0 To SecDataSet.Tables("Security").Rows.Count - 1
> > > > 'Get the current datarow from DataTable
> > > > Dim row As DataRow = SecDataSet.Tables("Security").Rows(i)
> > > >
> > > > 'Construct a valid security ticker
> > > > Dim strSecurity As String = row("Ticker").ToString
> > > >
> > > > 'Calling a function that will return historical data for a
> > > > security
> > > > Dim oData As Object = GetHistoricalData(strSecurity)
> > > >
> > > > 'Add historical data to DataSet
> > > > For j = 0 To oData.GetUpperBound(0)
> > > > Dim NewRow As DataRow = HistDataSet.Tables("History").NewRow
> > > > NewRow("Ticker") = row("Ticker").ToString
> > > > NewRow("Date") = Convert.ToDateTime(oData(j, 0))
> > > > NewRow("Price") = Convert.ToSingle(oData(j, 1))
> > > > HistDataSet.Tables("History").Rows.Add(NewRow)
> > > > Next
> > > >
> > > > HistDataSet.Tables("History").AcceptChanges()
> > > > Dim count As Integer = oData.GetUpperBound(0)
> > > > row("LastUpdate") = Convert.ToDateTime(oData(count, 0))
> > > > row("DataCount") = Convert.ToInt32(count)
> > > > SecDataSet.Tables("Security").AcceptChanges()
> > > >
> > > > 'Update database with the updated information
> > > > SecDataAdapter.Update(SecDataSet, "Security")
> > > > HistDataAdapter.Update(HistDataSet, "History")
> > > > Next
> > > >
> > > > 'Display results
> > > > Dim StatusForm As frmStatus
> > > > StatusForm = New frmStatus()
> > > > StatusForm.MdiParent = Me
> > > > StatusForm.DataGrid1.DataSource = SecDataSet.DefaultViewManager
> > > > StatusForm.Show()
> > > >
> > > > 'Close connection
> > > > myConn.Close()
> > > > -------------------------code
> > > > ends------------------------------------------
> > > >
> > > > The code failed to update the Access database with the data. I did
not
> > > > encounter any run-time error while executing the code. What
surprises
> > > > me is that the StatusForm->DataGrid1 shows that the SetDataSet
> > > > contained the historical data.
> > > >
> > > > Could someone please shed some light how I may rectify the problem?
> > > >
> > > > Thanks
> > > > Chris
> > >
> > >
> >
> >
>
>