PC Review


Reply
Thread Tools Rate Thread

DataAdapter.Update Command Failed To Update Database

 
 
Chris Lee
Guest
Posts: n/a
 
      3rd Aug 2004
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
 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      3rd Aug 2004
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



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      3rd Aug 2004
Chris,

Almost forever the same problem.

> HistDataSet.Tables("History").AcceptChanges()


' This means accept the changes as if they where already updated and set the
changed, updated and deleted rowstates to updated..

> Dim count As Integer = oData.GetUpperBound(0)
> row("LastUpdate") = Convert.ToDateTime(oData(count, 0))
> row("DataCount") = Convert.ToInt32(count)
> SecDataSet.Tables("Security").AcceptChanges()


' The same as above.
So try it with just removing those two.

>
> 'Update database with the updated information
> SecDataAdapter.Update(SecDataSet, "Security")
> HistDataAdapter.Update(HistDataSet, "History")
> Next


The DataAdapter.update has a build in acceptchanges for a dataset.

I hope this helps?

Cor


 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      3rd Aug 2004
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

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      3rd Aug 2004
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

> >
> >

>
>



 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      3rd Aug 2004
Watch where you put those acceptchanges commands. Right before calling
update, add a debug.Assert(dataSet.HasChanges) for each update and verify
that there are changes to update. That looks like the culprit.

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"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



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      4th Aug 2004
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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris Lee
Guest
Posts: n/a
 
      4th Aug 2004
Thanks for the advice. I have removed the dataset AcceptChanges
command just prior to the dataadapter Update command. Now, I am
getting an error when executing the Update command:

Unhandled exception of type System.InvalidOperation.Exception occurred
in system.dll. Additional information: Dynamic SQL generation for
UpdateCommand is not supported against a SelectCommand that does not
return any key column information.

Does that mean that the error occurred because I did not identify the
PrimaryKey? I left out the PrimaryKey because none of the columns in
the datatable are unique.
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      4th Aug 2004
Chris,

You are right, and than put this as well before your fills and maybe it will
be gone.

da.MissingSchemaAction = MissingSchemaAction.AddWithKey

I hope this helps?

Cor


 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      4th Aug 2004
Chris,

"Chris Lee" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the advice. I have removed the dataset AcceptChanges
> command just prior to the dataadapter Update command. Now, I am
> getting an error when executing the Update command:
>
> Unhandled exception of type System.InvalidOperation.Exception occurred
> in system.dll. Additional information: Dynamic SQL generation for
> UpdateCommand is not supported against a SelectCommand that does not
> return any key column information.
>
> Does that mean that the error occurred because I did not identify the
> PrimaryKey? I left out the PrimaryKey because none of the columns in
> the datatable are unique.


If you want commandbuilder to work with updates, the table has to have a
primary key.
Otherwise, do create Insert/Update/Delete commands by yourself (even better
than using command builder).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error in update command using dataadapter nannu Microsoft C# .NET 2 5th Feb 2007 04:10 AM
.net 1.1 DataAdapter.Update() command Steven Spencer \(Spinalogic\) Microsoft Dot NET Framework 0 17th Jan 2007 11:04 PM
DataAdapter changes insert-command at Update Patrick Microsoft ADO .NET 3 12th Dec 2006 06:42 PM
DataAdapter and Update command Julia Sats Microsoft ADO .NET 2 11th Sep 2003 09:27 AM
about DataAdapter and Update command Julia Sats Microsoft VB .NET 1 9th Sep 2003 10:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.