PC Review


Reply
Thread Tools Rate Thread

Adding a record to an Access db using DataAdapter.Update

 
 
Winshent
Guest
Posts: n/a
 
      15th Jul 2005
I need help with this. v simple.. but ive read a few postings regarding
this subject, but mine still doesnt work..

my problem lies with the insert command.. here is the output
###################################################
INSERT INTO tblCustomer( CustomerID , FirstName , LastName , Email )
VALUES ( ? , ? , ? , ? )
###################################################

Do i have to manually create this command?

Hers is my code below.

Public Function AddCustomer( _
ByVal CustomerID As Int64, _
ByVal Firstname As String, _
ByVal LastName As String, _
ByVal Email As String) as string

Dim ds As DataSet
Dim myTable As DataTable
Dim myNewRow As DataRow

ds = GetData("SELECT * FROM tblCustomer", "Customers")
myTable = ds.Tables("Customers")

myNewRow = myTable.NewRow
myNewRow.BeginEdit()
myNewRow.Item("CustomerID") = CustomerID
myNewRow.Item("FirstName") = Firstname
myNewRow.Item("LastName") = LastName
myNewRow.Item("Email") = Email
myNewRow.EndEdit()
ds.Tables("Customers").Rows.Add(myNewRow)

Dim s As String

s = "SELECT CustomerID, Firstname, LastName, Email FROM tblCustomer"

Dim da As OleDbDataAdapter = GetDataAdapter(s)
Dim cb As OleDbCommandBuilder
cb = New OleDbCommandBuilder(da)
da.UpdateCommand = cb.GetUpdateCommand
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand

Try

da.Update(ds, myTable.TableName)
ds.AcceptChanges()

Catch ex As Exception
Return (ex.ToString) & da.InsertCommand.CommandText()
Finally
ds.Dispose()
End Try



Thanks in advance

 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      15th Jul 2005
Hi,

http://msdn.microsoft.com/library/de...andbuilder.asp

Ken
--------------------
"Winshent" <winshent-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I need help with this. v simple.. but ive read a few postings regarding
this subject, but mine still doesnt work..

my problem lies with the insert command.. here is the output
###################################################
INSERT INTO tblCustomer( CustomerID , FirstName , LastName , Email )
VALUES ( ? , ? , ? , ? )
###################################################

Do i have to manually create this command?

Hers is my code below.

Public Function AddCustomer( _
ByVal CustomerID As Int64, _
ByVal Firstname As String, _
ByVal LastName As String, _
ByVal Email As String) as string

Dim ds As DataSet
Dim myTable As DataTable
Dim myNewRow As DataRow

ds = GetData("SELECT * FROM tblCustomer", "Customers")
myTable = ds.Tables("Customers")

myNewRow = myTable.NewRow
myNewRow.BeginEdit()
myNewRow.Item("CustomerID") = CustomerID
myNewRow.Item("FirstName") = Firstname
myNewRow.Item("LastName") = LastName
myNewRow.Item("Email") = Email
myNewRow.EndEdit()
ds.Tables("Customers").Rows.Add(myNewRow)

Dim s As String

s = "SELECT CustomerID, Firstname, LastName, Email FROM tblCustomer"

Dim da As OleDbDataAdapter = GetDataAdapter(s)
Dim cb As OleDbCommandBuilder
cb = New OleDbCommandBuilder(da)
da.UpdateCommand = cb.GetUpdateCommand
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand

Try

da.Update(ds, myTable.TableName)
ds.AcceptChanges()

Catch ex As Exception
Return (ex.ToString) & da.InsertCommand.CommandText()
Finally
ds.Dispose()
End Try



Thanks in advance


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a new record at subform should update an existing record (not create new record) Mark Kubicki Microsoft Access Form Coding 1 16th Jan 2009 08:34 AM
Update A Record In Access. Not Adding But Editing internacio Microsoft Excel Programming 0 31st Jan 2006 03:40 PM
How best to update DataAdapter to make DataGrid update immediately like table in Access would John Edens Microsoft Dot NET Framework Forms 1 5th Aug 2005 07:44 AM
Adding a record to an Access db using DataAdapter.Update Winshent Microsoft VB .NET 1 15th Jul 2005 01:45 AM
DataAdapter.Update() adding row with identity field PeterB Microsoft Dot NET Compact Framework 0 26th Aug 2003 05:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 AM.