473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Adding a record to an Access db using DataAdapter.Update

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

Nov 21 '05 #1
1 1208
Hi,

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

Ken
--------------------
"Winshent" <wi*************@yahoo.co.uk> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
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
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: Richard | last post by:
In normal asp i used --------- objRS.Open "tbl_Nieuws", objConn, 1, 3 objRS.AddNew objRS.Fields("N_Datum") = FormatDateTime(Now(),2) objRS.Fields("N_Title") =...
3
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
0
by: HS1 | last post by:
Hello all I have a DataGrid1 presenting records of a table ("clients") in a Access Database through a DataSet (ds) using DataAdapter (da1) and buttons "add", "save" and"delete" buttons with the...
2
by: dbuchanan | last post by:
Hello, My insert results in two records - or better stated the temporary record (with the temporary ID value of -1) stays as the stored procedure returns the new record with its data base...
1
by: Rich | last post by:
Hello, I can update a dataset from my client app using a dataAdapter.Updatecommand when I add parameter values outside of the param declaration. But If I add the param values inline with the...
7
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.