Hi, all,
I only found one way to make the update successful that is having the primary key field showing in the datagrid and using VB.net's build-in function to make data adapter, dataset and connection. This way I can use the method: OleDbDataAdapter1.Update(Ds1) to do all the insert, delete and update.
However, the records I need to display in the datagrid have to be based on a variable passed from the other form, say strScenarioName. So I have to mannuly write the SQL select statement cause the dataadapter wizard wouldn't recognized the variable. But using this way, the Da.Update(Ds) method won't work anymore. Do you think i need to hand write Update statement? Here is the code for loading and updating the datagrid. Thanks
Private da As OleDb.OleDbDataAdapter 'define dataAdapter's name. dataAdapter copies data from db to dataset
Private ds As DataSet 'define dataset name
Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
da.Update(ds, "Vendor")
MsgBox("Succeeded!")
Catch ex As Exception
MsgBox("nothing")
End Try
End Sub
Private Const strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=C:\SCOPT\GPLogiModData-0815.mdb;"
Private Sub Load1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Load1.Click
Dim strSQL As String = "SELECT * FROM TM_Vendor WHERE TM_Vendor.ScenarioName = '" & x & "'"
da = New OleDb.OleDbDataAdapter(strSQL, strConn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Vendor")
DataGrid1.DataSource = ds.Tables("Vendor")
DataGrid1.SetDataBinding(ds, "Vendor")
End Sub
'Class scope
Dim myDv As New System.Data.DataView
Dim strSQL As String = "SELECT * FROM TM_Vendor"
da = New OleDb.OleDbDataAdapter(str
ds = New DataSet
ds.Clear()
da.Fill(ds, "Vendor")
Me.myDv.Table = ds.Tables("Vendor")
Me.myDv.RowFilter = String.Format("ScenarioNam
Me.DataGrid1.DataSource = Me.myDv
You could also manually modify the Update and Insert Command Builder objects
In addtion you may need a CurrencyManager object for the DataView