473,386 Members | 1,812 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,386 software developers and data experts.

How to use a primary key query

Iam using VB6.0
i want to know the query of how to check for the record which is already in the database using the primary key
Feb 16 '07 #1
6 1175
Killer42
8,435 Expert 8TB
Iam using VB6.0
i want to know the query of how to check for the record which is already in the database using the primary key
How are you accessing the database? And what kind of database is it - an MDB file?
Feb 16 '07 #2
Well i am using VB6.0 nd SQL server 2000,i am connecting via a string.can u tell how to look wheather a record already exists or not before adding a new record using the primary key,plz give me the query
Feb 16 '07 #3
suppose you have a table having structure like this
PurMaster-Fields(PurID,PDt,Amt)
Write an sql query like the following before you start insert to database
"Select Count(*) from Purmaster where PurID=" & val(txt_PurID.text)"
and if the query results >0 then avoid updating
Feb 17 '07 #4
In the above note the PurID is the Primary Key
Feb 17 '07 #5
Thanx,but can you give the full code using an example to check wheather a record exists or not before adding the record
Feb 19 '07 #6
Expand|Select|Wrap|Line Numbers
  1. Dim rs As New ADODB.Recordset
  2. rs.Open "Select count(*) from Purmaster where PurID=" & Val(txt_PurID.Text), conn, adOpenForwardOnly, adLockReadOnly
  3. If rs(0) > 0 Then
  4.     MsgBox "the Pur ID is already exist. please enter another one...", vbCritical
  5.     rs.Close
  6.     Exit Sub
  7. End If
  8. rs.Close
  9. 'Code for adding project
Feb 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: John Simmons | last post by:
How is it that even though I have the column "username" in my database set as a Primary key, using my PHP script to add new users to the database works without any errors even when signing up using...
4
by: deko | last post by:
I have a Make Table query that creates a fairly large table. The Make Table query populates the new table with one AutoNumber field (which is taken form another unrelated table as part of the...
5
by: Geoff Cayzer | last post by:
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section which is included below and was hoping for some comment on the article. -------------- Almost never use this auto-number...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: misscrf | last post by:
Ok I have 2 issues. 1) I have a main candidate form with 2 subforms on a tab control: http://www.geocities.com/misscrf/images/contactcontinouscheckbox.jpg I have been encouraged to add these...
3
by: Jeff Amiel | last post by:
7.4.2 running on FreeBSD 5.4.2 I have a table (called "draft" ) that has a bigserial as the primary key. "check_id bigserial NOT NULL" I do NOT have an additional index on that column. I...
1
by: Jeweladdict | last post by:
I have 2 linked tables, The first table (PRODUCT) has product name, pricing, size, etc with an autonumber primary key. The second table is a UPC table with the primary key from PRODUCT linked...
21
by: Killer42 | last post by:
Hi all. As has been mentioned here recently, I have a front-end database which just includes some queries and a bunch of (rather large) linked tables. For reasons of (very poor) performance, I had...
8
by: m.wanstall | last post by:
Hi All, This is similar to a question I asked earlier however this is following a more "correct" way of doing things. I have normalised and summarised an Exchange addressbook (a few thousand...
2
by: Danny | last post by:
Hello, We imported a bunch of tables from a database and realized that the primary keys weren't copied to the destination db. In order to re- create the keys, we need to know which tables have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.