473,385 Members | 2,013 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,385 software developers and data experts.

If Record Exist

36
HI,
What i trying to do is
when a user try to add new item that already in the table
(example try to add a "name" that already in the "Name_Table")
msgbox pops up and tell the user that the name is already in the table

is there anyway to do this in Visual basic 2005

Thanks (Any help)
Aug 3 '07 #1
11 4187
Use a sql statement something like

Select * from table where name='juan dela crus'

if the return value is 1 or more then the name is exist
Aug 3 '07 #2
gayano
36
Thanks

Could you give me a example vb code

Thank you
Aug 3 '07 #3
SAMPLE:


SQL = Select * from table where name='juan dela crus'

set rs = conn.execute(SQL)

if not rs.eof then

msgbox "Oyee file already exist ^__^"

end if


..hope that solve your problem ^__^
Aug 3 '07 #4
debasisdas
8,127 Expert 4TB
before inserting the record execute this

select count(name_field) from table_name where name_field= 'name';

if it returns 1 or more ,you can return the message and no need to execute the insert statment.
Aug 3 '07 #5
gayano
36
Thank you guys
Thank you veeeeeeeeeeeeeeeeeeeery much
Aug 3 '07 #6
gayano
36
sorry guys i need more info

What to do before writing those codes that you gave me.
cz im not verry good at sql

Im using sql server 2005


do i have open a connection to my database first??
can you give me A to Z example??
Aug 3 '07 #7
sorry guys i need more info

What to do before writing those codes that you gave me.
cz im not verry good at sql

Im using sql server 2005


do i have open a connection to my database first??
can you give me A to Z example??
Yes you need to open new connection first...

e.g.

Dim dbs As ADODB.Connection
Dim rec As ADODB.Recordset

Set dbs = New ADODB.Connection
Set rec = New ADODB.Recordset

sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDatabase.mdb"
dbs.Open sConnString
rec.Open "SELECT * FROM TABLE WHERE name='juan dela cruz'", dbs

If rec.EOF And rec.BOF Then
MsgBox "not exist"
Else
MsgBox "exist"
End If
Aug 3 '07 #8
Killer42
8,435 Expert 8TB
I think it might help a lot if you tell/show us what you've got so far. We don't know how you're storing the data yet.
Aug 3 '07 #9
gayano
36
This is What i done for inserting data?? this works greate but i dont want user to add same data again and again sowhat should i do??

at the time i dont have any diclaration fo sql conn... ,,,, (Dont mind about the Japanese Charactors in the msg box's)

Expand|Select|Wrap|Line Numbers
  1. Private Sub InsertData()
  2.         Dim Truckcode As Integer
  3.         Dim TruckNo As String
  4.         Dim TruckMake As String
  5.         Dim TruckRegDate As Date
  6.         Dim TruckOption As String
  7.         Dim TruckDriver As String
  8.         Dim TruckTons As Integer
  9.         Dim TruckSS As Date
  10.         Dim TruckSE As Date
  11.  
  12.  
  13.         Truckcode = CInt(txtTruckCode.Text)
  14.         TruckNo = txtTruckNo.Text
  15.         TruckMake = txtTruckMake.Text
  16.         TruckRegDate = CDate(txtmTruckRegDate.Text)
  17.         TruckOption = txtTruckOption.Text
  18.         TruckDriver = txtTruckDriver.Text
  19.         TruckTons = CInt(txtTruckTons.Text)
  20.         TruckSS = CDate(txtmTruckSS.Text)
  21.         TruckSE = CDate(txtmTruckSE.Text)
  22.  
  23.         Try
  24.             Me.TrucksTableAdapter.Insert(Truckcode, TruckNo, TruckMake, TruckRegDate, TruckOption, TruckDriver, TruckTons, TruckSS, TruckSE)
  25.             Me.TrucksTableAdapter.Update(Me.UnkouTrucks.Trucks)
  26.         Catch ex As Exception
  27.             MsgBox("入力間違ってます 管理人にお問い合わせしてください....っていうかガヤンに聞いて" & ex.Message)
  28.  
  29.         End Try
  30.         MsgBox("トラック1台追加されました", MsgBoxStyle.Information, "確認")
  31.  
  32.  
  33.  
  34.         ''**************** Update and Fill Truck Form **********************''
  35.  
  36.         Try
  37.  
  38.             Trucks.TrucksTableAdapter.Update(UnkouTrucks.Trucks)
  39.             Trucks.TrucksTableAdapter.Fill(UnkouTrucks.Trucks)
  40.         Catch ex As Exception
  41.             MsgBox("入力間違ってます 管理人にお問い合わせしてください....っていうかガヤンに聞いて" & ex.Message)
  42.         End Try
  43.  
  44.  
  45.         ''**************** Clear The form for the next entry *****************''
  46.         ClearForm()
  47.  
  48. End Sub
Thank you
Aug 3 '07 #10
Killer42
8,435 Expert 8TB
A lot of this is VB.Net-specific, so I can't help with it (I use "old faithful", VB6). But the simplest thing might be to put unique indexes on one or more of the fields. That way, the database would reject any duplicates, and you can just catch the exception.

Otherwise, you need to do a search for the new values before storing them. I don't know the syntax to do that with a "data adaptor".
Aug 4 '07 #11
gayano
36
Thank you killer42,

anyway when it catch the errors but unfortunatly it still insert the data.
any wrong in the code??

like where shoukd i catch the exception??

can someone do a example in here??!!
Aug 4 '07 #12

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

Similar topics

3
by: luna | last post by:
need to display a label if a record is not found - tried a few things but it appears to be ignoring me!! code is currently like this - you can also see the test i did - must be doing something...
7
by: Stephen Poley | last post by:
I have the following situation: - a table of employees, keyed on employee-id; - a table of training sessions, keyed on session-id; - a requirement to log who was present at which session, plus...
6
by: erick-flores | last post by:
Hello all, Form A & Form B Form B opens when I click on a button from Form A. How do I setup Form B so it will always let me insert new records. Because right know, when I click on the button...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
4
by: elainenguyen | last post by:
I am trying to write a code that seaching a record in 3 tables and if the record exist, show the data, if the record doesn't exist, show the warning message. The following is my code that I am...
4
by: is49460 | last post by:
Any help would be very appreciated!!! I have two tables: Main Data and Archived Data. Each table has the same fields (about 50 or so fields). Main data contains records that are updated every...
6
by: Matt | last post by:
I need some guidance on how to handle an issue. I have an .asp page that correctly queries a table and returns data if a 'job number' and week ending date exist and the user can update the...
1
by: sprasad123 | last post by:
Need bit of a help with Access to SQL subform queries i have upsized a Access DB. It also has a Access frontend. The upsized went ok. I relinked the Access linked table to SQL. When I try to add a...
5
by: Stephen | last post by:
Hello, I have 2 tables, one contains log of all incoming phone calls, and the other one is simply a phone book. I want to fetch caller's name if it's already exist in the phone book, and if it...
3
by: Constantine AI | last post by:
Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below; Dim strSQL As String Dim strSQL2 As String Dim Reply As String Dim db As...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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 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.