Hi. I'm using VB 6.0, and I'm connecting to an Access database. I open two
tables which are joined.
I'm trying to insert a new record, and only have one of the tables affected.
I'm not having much success. I can open the records, surf through them,
etc. I find the .ADDNEW ado function doesn't work properly when you have
multiple tables open.
Each table has an auto numbered field which serves as the primary key
(students.studentCode, and instructors.instructorCode)
Dim db As New Connection
Dim adoRecordSet As New Recordset
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _
"\ddt.mdb;Mode=ReadWrite|Share Deny None;Persist Security
Info=False"
adoRecordSet.Open "select * from students, instructors " _
& "WHERE students.instructorCode = 1 AND students.instructorCode =
instructors.instructorCode", _
db, adOpenStatic, adLockPessimistic
db.Execute ("INSERT INTO students (students.firstName,
students.lastName, students.instructorCode) " _
& "VALUES ('First', 'Last', '7')")
Why does this insert not work? The syntax looks right to me. When I use it
I get error -2147217900 (that's a pretty big negative number)
Is there a better way to add a new record? How do I make sure that my
record set can see the new record, and hence have my controls be able to
display the new record? IE: I press the Next or Previous controls to
traverse the records, will my new record show?
Also, for deleting records is this my best bet:
db.Execute ("DELETE FROM students WHERE studentCode = " & txtStudentCode)
Adrian 4 5143
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message
news:3d*******************@news20.bellglobal.com.. .
Ok, I got a new record inserted, db.Execute ("INSERT INTO students
(firstName, lastName, instructorCode) " _
& "VALUES ('New 2', 'Addition 2', '7')")
But using adorecordset.movenext or adorecordset.movelast cannot traverse to
the new entry.
I tried adorecordset.requery. This should show the new record, but does
not. If I add a new record, close the program, then reopen it, the new
record is loaded with the query.
After I do an insert, how do I get the adorecordset (Recordset object) to
include this new row? Dim db As New Connection Dim adoRecordSet As New Recordset
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _ "\ddt.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
adoRecordSet.Open "select * from students, instructors " _ & "WHERE students.instructorCode = 1 AND students.instructorCode = instructors.instructorCode", _ db, adOpenStatic, adLockPessimistic
db.Execute ("INSERT INTO students (students.firstName, students.lastName, students.instructorCode) " _ & "VALUES ('First', 'Last', '7')")
Also, I'm loading the data into forms using:
Set txtFirstName.DataSource = adoRecordSet
txtFirstName.DataField = "students.firstName"
Set txtLastName.DataSource = adoRecordSet
txtLastName.DataField = "students.lastName"
And I'm traversing the records with statements like adoRecordSet.MoveFirst,
adoRecordSet.MoveLast etc.
Adrian
When you do a requery than you do a movelast to see the newest record
greets John
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> schreef in bericht
news:G6********************@news20.bellglobal.com. .. "Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message news:3d*******************@news20.bellglobal.com.. .
Ok, I got a new record inserted, db.Execute ("INSERT INTO students (firstName, lastName, instructorCode) " _ & "VALUES ('New 2', 'Addition 2', '7')")
But using adorecordset.movenext or adorecordset.movelast cannot traverse
to the new entry.
I tried adorecordset.requery. This should show the new record, but does not. If I add a new record, close the program, then reopen it, the new record is loaded with the query.
After I do an insert, how do I get the adorecordset (Recordset object) to include this new row?
Dim db As New Connection Dim adoRecordSet As New Recordset
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &
_ "\ddt.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
adoRecordSet.Open "select * from students, instructors " _ & "WHERE students.instructorCode = 1 AND students.instructorCode
= instructors.instructorCode", _ db, adOpenStatic, adLockPessimistic
db.Execute ("INSERT INTO students (students.firstName, students.lastName, students.instructorCode) " _ & "VALUES ('First', 'Last', '7')")
Also, I'm loading the data into forms using:
Set txtFirstName.DataSource = adoRecordSet txtFirstName.DataField = "students.firstName"
Set txtLastName.DataSource = adoRecordSet txtLastName.DataField = "students.lastName"
And I'm traversing the records with statements like
adoRecordSet.MoveFirst, adoRecordSet.MoveLast etc. Adrian
"Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message
news:G6********************@news20.bellglobal.com. .. "Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message news:3d*******************@news20.bellglobal.com.. .
Ok, I got a new record inserted, db.Execute ("INSERT INTO students (firstName, lastName, instructorCode) " _ & "VALUES ('New 2', 'Addition 2', '7')")
But using adorecordset.movenext or adorecordset.movelast cannot
traverse to the new entry.
adoRecordSet.Open "select * from students, instructors " _ & "WHERE students.instructorCode = 1 AND
students.instructorCode = instructors.instructorCode", _ db, adOpenStatic, adLockPessimistic
As I read it, your new record has instructorCode 7, and your recordset
is filtering for records with instructorCode 1, so it is correctly not
showing the new record after a refresh.
"Steve Gerrard" <no*************@comcast.net> wrote in message
news:s8********************@comcast.com... "Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message news:G6********************@news20.bellglobal.com. .. "Adrian Parker" <ad***********@NOSPAMsympatico.ca> wrote in message news:3d*******************@news20.bellglobal.com.. .
Ok, I got a new record inserted, db.Execute ("INSERT INTO students (firstName, lastName, instructorCode) " _ & "VALUES ('New 2', 'Addition 2', '7')")
But using adorecordset.movenext or adorecordset.movelast cannot
traverse to the new entry.
adoRecordSet.Open "select * from students, instructors " _ & "WHERE students.instructorCode = 1 AND students.instructorCode = instructors.instructorCode", _ db, adOpenStatic, adLockPessimistic
As I read it, your new record has instructorCode 7, and your recordset is filtering for records with instructorCode 1, so it is correctly not showing the new record after a refresh.
I noticed after.
My big concern now is how do I do a query, which finds the value of just one
field, and stores that in a small variable (int or something). I don't want
to use an entire recordset just to get one field.
Adrian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: salamol |
last post by:
I has a strange question.
My company is using a old system with Win NT 4.0 Server + MS SQL 7.0.
The system is busy and handle a lot of SELECTs and INSERTs all the time.
Sometimes, some...
|
by: Robin Tucker |
last post by:
Hi there,
I have a database on my test machine that will need to be installed on users
machines. I would like to create the database with the given schema on the
users machine and also with...
|
by: fumanchu |
last post by:
I need to insert records into a Sybase database via a linked table.
I have a valid, tested DSN ODBC connection to the Sybase database
named 'SBA9link'. I also have created a link to a table in...
|
by: bob |
last post by:
In an effort to keep my UI responsive I have begun to run my time intensive
methods on their own thread and in particular the database inserts.
I open my DB connection in the constructor and close...
|
by: Nemisis |
last post by:
hi guys,
Currently converting an old classic asp system to a OOP asp.net
application. We are building the new application using a 3 tier
arcitecture and i was wondering about the following.
...
| |
by: shsandeep |
last post by:
The ETL application loaded around 3000 rows in 14 seconds in a Development
database while it took 2 hours to load in a UAT database.
UAT db is partitioned.
Dev db is not partitioned.
the...
|
by: rich |
last post by:
I have a PHP5 application that accepts external messages, and inserts
them into a database. It's rather high traffic.. the server could be
receiving thousands at a time, and recently mysql has...
|
by: Marijn |
last post by:
Hello everybody,
I am new to PHP and working on extending my knowledge of OOP. The
posts in this group concerned with whether or not to use an OO
approach when programming in PHP is not what I...
|
by: orfiyus |
last post by:
whats good
I am working on a php script. It takes in user input from a text field and then queries the database for it. If the input is found in the database then script performs a delete query...
|
by: Tommy Hayes |
last post by:
Hello all,
I want to use the SQL Server 2005 Tuning Advisor on our database, and
I'm hoping someone here can just confirm the steps for me. We have a
10GB database that has a number of...
|
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,...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| | |