Hi John,
What you need to do is to create a selectcommand, insertcommand,
updatecommand with your dataAdapter. Note: the DataAdapter does not
work with MS Access - well except for the Select command, but none of
the action commands like Insert/Update/Delete. But they work well with
MS Sql Server (and probably Oracle)
Imports System
Imports System.Data.SqlClient
...
'--form level variables here
Dim da as New SqlDataAdapter, ds As New Dataset
Dim conn As New SqlConnection
Private Sub Form1_Load(...)
conn.ConnectionString = "Data Source=yourSvr;Initial
Catalog=yourDB;Integrated Security=True"
da.SelectCommand = New SqlCommand
da.InsertCommand = New SqlCommand
da.UpdateCommand = New SqlCommand
da.SelectCommand.connection = conn
da.InsertCommand.connection = conn
da.UpdateCommand.connection = conn
da.SelectCommand..CommandText = "Select * From tblx Where..."
da.InsertCommand.CommandText = "Insert Into tblx Select @f1, @f2 @f3"
da.UpdateCommand.CommandText = "Update tblx Set f1 = @f1, f2 = @f2, f3 =
@f3 Where ID = @ID"
da.InsertCommand.Parameters.Add("@f1", SqlDBType.Varchar, 50, "f1")
...
da.UpdateCommand.Parameters.Add("@f1", SqlDbType.Varchar, 50, "f1")
da.Fill(ds, "tbl_Local")
End Sub
Private Sub Insert_Update()
Dim dr As DataRow
dr = ds.Tables("tbl_Local").NewRow
dr.BeginEdit
dr("f1") = "test1"
dr("f2") = "test2"
dr("f3") = "test3
dr.EndEdit
ds.Tables("tbl_Local").Rows.Add(dr)
da.Update(ds, "tbl_Local")
End Sub
So you create tbl_Local on the fly with the da.Fill command. Then
whenever you add a new row to tbl_Local or edit a field in one of the
rows - the dataAdapter da will automatically know what happened. You
call the da.Update command -- for Inserts and Update (and deletes also).
This will update the table on the server with either a new row or an
edit update on a particular row. tbl_local is a mirror image of the
server table in your local memory.
Rich
*** Sent via Developersdex
http://www.developersdex.com ***