|
-
Mar 3rd, 2004, 11:16 AM
#1
Thread Starter
New Member
Update method not working
Well, I took out the the exception handler and got this error message at <adpCarriers.Update(xDataSet, "tblcarrier")> :
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
Need help, thanks.
Code:
Public Sub ConnectToAccess()
Dim LastError As Exception
'LastError = Server.GetLastError()
Dim conn As New System.Data.OleDb.OleDbConnection
Dim adpCarriers As New System.Data.oledb.OleDbDataAdapter
Dim mySelectQuery As String = "SELECT CarrierID, Name FROM tblCarrier"
'Dim myCommand As New System.Data.OleDb.OleDbCommand(mySelectQuery, conn)
adpCarriers.SelectCommand = New System.Data.OleDb.OleDbCommand(mySelectQuery, conn)
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
"F:\tdeseamus\Vendor_Compliance.mdb"
adpCarriers.TableMappings.Add("Table", "tblCarrier")
'Try
conn.Open()
' Insert code to process data.
MsgBox("made it")
'mydataset.Tables.Add("tblCarrier")
adpCarriers.Fill(mydataset)
t = mydataset.Tables(0)
'DataGrid1.DataSource = t
'DataGrid1.DataBindings.Add(New Binding("BindingContext", mydataset, "tblcarrier"))
TextBox1.DataBindings.Add(New Binding("Text", mydataset, "tblcarrier.name"))
TextBox2.DataBindings.Add(New Binding("Text", mydataset, "tblcarrier.carrierid"))
MsgBox("made it1")
mydataset.Tables("tblcarrier").Rows(0).Item("name") = "Severian"
'mydataset.Tables("tblcarrier").Rows(0).Item("carrierid") = "ZZZZ"
' Check for changes with the HasChanges method first.
If Not mydataset.HasChanges(DataRowState.Modified) Then Exit Sub
' Create temporary DataSet variable.
Dim xDataSet As DataSet
MsgBox("made it2")
' GetChanges for modified rows only.
xDataSet = mydataset.GetChanges(DataRowState.Modified)
' Check the DataSet for errors.
If xDataSet.HasErrors Then
' Insert code to resolve errors.
End If
MsgBox("made it3")
' After fixing errors, update the data source with the DataAdapter
' used to create the DataSet.
adpCarriers.Update(xDataSet, "tblcarrier")
MsgBox("Made it4")
'Catch ex As Exception
'MsgBox(ErrorNumber)
'Finally
conn.Close()
'End Try
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|