G
Guest
Hi all,
I am having trouble with updating my data in an Access database. here is my
code:
Imports System.Data.OleDb
Dim AppPath As String = Mid(Application.ExecutablePath, 1,
Len(Application.ExecutablePath) - 14)
Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source =
d:\comic2006\comic.mdb"
Dim dbConn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection(strConn)
Dim DSet As New DataSet, SQLStr As String
Dim cmd As System.Data.OleDb.OleDbCommand
Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dbConn.Open()
Dim tRow As DataRow, tTbl As DataTable
With dbAdaptr
.TableMappings.Add("Table", "issues")
SQLStr = "Select * from issues WHERE series = " &
CType(cmbSeries.SelectedItem, ComboItem).ItemData & " AND issuea = '" &
CType(cmbIssues.SelectedItem, ComboItem).Item & "' AND issuen = " &
CType(cmbIssues.SelectedItem, ComboItem).ItemData
cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
cmd.CommandType = CommandType.Text
.SelectCommand = cmd
.Fill(DSet)
' .Dispose()
End With
' DSet.AcceptChanges()
tTbl = DSet.Tables.Item(0)
' DSet.Dispose()
dbConn.Close()
' Load the issue information into the form
For Each tRow In tTbl.Rows
tRow("month") = txtMM.Text
tRow("day") = txtDD.Text
tRow("year") = txtYY.Text
tRow("pages") = txtPages.Text
tRow("ad pages") = txtAdPages.Text
tRow("price") = txtCoverPrice.Text
tRow("stories") = txtStories.Text
tRow("cover caption") = txtCoverCaption.Text
tRow("notes") = txtIssueNotes.Text
Next
dbAdaptr.Update(DSet)
dbAdaptr.Dispose()
tTbl.Dispose()
The error I get is:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.
I am trying to re-write an app from VB6 to vb.net and this is all very new
to me, especially the database access, so forgive me if the error is obvious.
Thanks in advance for your help,
George
I am having trouble with updating my data in an Access database. here is my
code:
Imports System.Data.OleDb
Dim AppPath As String = Mid(Application.ExecutablePath, 1,
Len(Application.ExecutablePath) - 14)
Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source =
d:\comic2006\comic.mdb"
Dim dbConn As System.Data.OleDb.OleDbConnection = New
System.Data.OleDb.OleDbConnection(strConn)
Dim DSet As New DataSet, SQLStr As String
Dim cmd As System.Data.OleDb.OleDbCommand
Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dbConn.Open()
Dim tRow As DataRow, tTbl As DataTable
With dbAdaptr
.TableMappings.Add("Table", "issues")
SQLStr = "Select * from issues WHERE series = " &
CType(cmbSeries.SelectedItem, ComboItem).ItemData & " AND issuea = '" &
CType(cmbIssues.SelectedItem, ComboItem).Item & "' AND issuen = " &
CType(cmbIssues.SelectedItem, ComboItem).ItemData
cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
cmd.CommandType = CommandType.Text
.SelectCommand = cmd
.Fill(DSet)
' .Dispose()
End With
' DSet.AcceptChanges()
tTbl = DSet.Tables.Item(0)
' DSet.Dispose()
dbConn.Close()
' Load the issue information into the form
For Each tRow In tTbl.Rows
tRow("month") = txtMM.Text
tRow("day") = txtDD.Text
tRow("year") = txtYY.Text
tRow("pages") = txtPages.Text
tRow("ad pages") = txtAdPages.Text
tRow("price") = txtCoverPrice.Text
tRow("stories") = txtStories.Text
tRow("cover caption") = txtCoverCaption.Text
tRow("notes") = txtIssueNotes.Text
Next
dbAdaptr.Update(DSet)
dbAdaptr.Dispose()
tTbl.Dispose()
The error I get is:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.
I am trying to re-write an app from VB6 to vb.net and this is all very new
to me, especially the database access, so forgive me if the error is obvious.
Thanks in advance for your help,
George