|
-
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
-
Mar 3rd, 2004, 11:34 AM
#2
Thread Starter
New Member
Solved it
Added the line
adpCarriers.SelectCommand = New System.Data.OleDb.OleDbCommand(mySelectQuery, conn)
Update method needs this for some reason.
-
Mar 3rd, 2004, 11:39 AM
#3
Addicted Member
Code:
Public Sub ConnectToAccess()
Dim ret As Integer
Try
Me.SqlConnection1.Open()
Me.BindingContext(DataSet1, "Products").EndCurrentEdit()
ret = Me.SqlDataAdapter1.Update(DataSet1.Tables("Products"))
If (ret <> 0) Then
DataSet1.Tables("products").AcceptChanges()
Else
DataSet1.Tables("products").RejectChanges()
End If
MessageBox.Show("Records changed: " & ret)
Catch ex As Exception
DataSet1.Tables("products").RejectChanges()
MessageBox.Show(ex.Message)
Finally
'Me.SqlConnection1.Close()
End Try
end sub
this is update code to update, but i use a SqlConnections and SqlCommand. The concept is simular just change the code to what u need.
hope it helps if not sorry!
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
|