473,657 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add record to Access Database


I am using the following code to add a record to an Access database. If I
run the code and go to the database the code is there, but if as soon as I
run the code I try to access the record with the SQL statement: strSQL =
"SELECT Target_NO FROM " & strtablename & " WHERE ID = " & intMaxID, I don't
get the record that I just added although it does have the highest ID
number. Is the code just running faster than the database gets updated?

Thanks,

Thomas
'set up the database connection, dataAdapter, and dataSet

Dim myConnection As OleDbConnection
myConnection = New OleDbConnection (strConn)
myConnection.Op en()

Dim da As New OleDb.OleDbData Adapter(strSQL, myConnection)
Dim cb As New OleDb.OleDbComm andBuilder(da)
Dim ds As New DataSet
Dim newRow As DataRow

Try
da.FillSchema(d s, SchemaType.Sour ce, strTable)
newRow = ds.Tables(strTa ble).NewRow()
newRow("ID") = aryAddRecord(0)
newRow("DTG") = aryAddRecord(1)
newRow("POO") = aryAddRecord(2)
newRow("POO_Alt ") = Val(aryAddRecor d(3))
newRow("POI") = aryAddRecord(4)
newRow("POI_Alt ") = Val(aryAddRecor d(5))
newRow("Distanc e") = Val(aryAddRecor d(6))
newRow("Directi on") = Val(aryAddRecor d(7))
If intImportType = 2 Then
newRow("Db") = Val(aryAddRecor d(8))
newRow("Velocit y") = Val(aryAddRecor d(9))
End If
newRow("Target_ NO") = aryAddRecord(10 )
If intImportType = 2 Then
If Len(aryAddRecor d(11)) < 1 Then
aryAddRecord(11 ) = "false"
End If
End If
newRow("Weapon_ Type") = aryAddRecord(11 )
newRow("Confirm ed") = Val(aryAddRecor d(12))

'add the new row to the dataSet
ds.Tables(strTa ble).Rows.Add(n ewRow)

'sent the updated dataSet to the database
da.Update(ds, strTable)

Catch oException As OleDbException
MessageBox.Show (oException.Mes sage)

Catch oException As Exception
MessageBox.Show (oException.Mes sage)

End Try

myConnection.Cl ose()

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
2 1344
Hi Thomas,

Shouldn't be. How are you setting the value of intmaxid? Which row do you
get?

Bernie Yaeger

<th*****@msala. net> wrote in message
news:42******** *************** @news.newsdemon .com...

I am using the following code to add a record to an Access database. If I
run the code and go to the database the code is there, but if as soon as I
run the code I try to access the record with the SQL statement: strSQL =
"SELECT Target_NO FROM " & strtablename & " WHERE ID = " & intMaxID, I
don't
get the record that I just added although it does have the highest ID
number. Is the code just running faster than the database gets updated?

Thanks,

Thomas
'set up the database connection, dataAdapter, and dataSet

Dim myConnection As OleDbConnection
myConnection = New OleDbConnection (strConn)
myConnection.Op en()

Dim da As New OleDb.OleDbData Adapter(strSQL, myConnection)
Dim cb As New OleDb.OleDbComm andBuilder(da)
Dim ds As New DataSet
Dim newRow As DataRow

Try
da.FillSchema(d s, SchemaType.Sour ce, strTable)
newRow = ds.Tables(strTa ble).NewRow()
newRow("ID") = aryAddRecord(0)
newRow("DTG") = aryAddRecord(1)
newRow("POO") = aryAddRecord(2)
newRow("POO_Alt ") = Val(aryAddRecor d(3))
newRow("POI") = aryAddRecord(4)
newRow("POI_Alt ") = Val(aryAddRecor d(5))
newRow("Distanc e") = Val(aryAddRecor d(6))
newRow("Directi on") = Val(aryAddRecor d(7))
If intImportType = 2 Then
newRow("Db") = Val(aryAddRecor d(8))
newRow("Velocit y") = Val(aryAddRecor d(9))
End If
newRow("Target_ NO") = aryAddRecord(10 )
If intImportType = 2 Then
If Len(aryAddRecor d(11)) < 1 Then
aryAddRecord(11 ) = "false"
End If
End If
newRow("Weapon_ Type") = aryAddRecord(11 )
newRow("Confirm ed") = Val(aryAddRecor d(12))

'add the new row to the dataSet
ds.Tables(strTa ble).Rows.Add(n ewRow)

'sent the updated dataSet to the database
da.Update(ds, strTable)

Catch oException As OleDbException
MessageBox.Show (oException.Mes sage)

Catch oException As Exception
MessageBox.Show (oException.Mes sage)

End Try

myConnection.Cl ose()

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #2

Most of my records are added in large groups from text files. The code
queries for the largest ID number, adds one to it, then starts adding
records. Works great for my situation.

The form I am working on, that has this problem, is used to manual add one
record at a time. When the form opens it queries for the largest ID, adds
one, and uses that for the ID of the first added record. When the user
clicks the add record button, the record is added and the query for the
highest ID is ran again. The ID it returns is the same as before the record
was added. If I go to the database and look, the record I just added is
there.

Hope all that makes sense.

If you have time look at my other post, you may can help me with it.

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3

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

Similar topics

1
5412
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the database so I could sort the records by the date at which they were entered. Well now I've deleted some of those records so its of course causing gaps in the records. The record number in Access no longer matches my record number that I...
10
12692
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be certain that MyVar will be set to the key-field value that was created when the Append query ran. Now, there are other ways to do it - I know - that will ensure you 'nab' the correct record. But I was wondering
0
4096
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access with "No locks" as the default, so that optimistic record locking should take place, and "Open databases using record-level locking" is selected. Each Java thread gets a new connection to the database, then updates its record. One of my users has...
4
2389
by: corey11 | last post by:
I'm a very low-level developer with limited VB knowledge but nonetheless was able to put together a very user-friendly and extremely helpful Access 97 database for my company some 10 years back. We use the database for inventory, job costing, employee records, timecard recording, nearly everything except the hard core accounting. The database is shared by 20 users over a network. Every 3 or 4 years I archive and purge the data to keep the...
25
20546
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record, and try to move to another record and get an Access error "Record is too large". The record is only half filled, with many empty fields. If I remove the added data or delete some older data, then it saves ok and works fine again. Whenever I'm...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.