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)
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
Thanks
Could you give me a example vb code
Thank you
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 ^__^
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.
Thank you guys
Thank you veeeeeeeeeeeeeeeeeeeery much
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??
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
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.
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) - Private Sub InsertData()
-
Dim Truckcode As Integer
-
Dim TruckNo As String
-
Dim TruckMake As String
-
Dim TruckRegDate As Date
-
Dim TruckOption As String
-
Dim TruckDriver As String
-
Dim TruckTons As Integer
-
Dim TruckSS As Date
-
Dim TruckSE As Date
-
-
-
Truckcode = CInt(txtTruckCode.Text)
-
TruckNo = txtTruckNo.Text
-
TruckMake = txtTruckMake.Text
-
TruckRegDate = CDate(txtmTruckRegDate.Text)
-
TruckOption = txtTruckOption.Text
-
TruckDriver = txtTruckDriver.Text
-
TruckTons = CInt(txtTruckTons.Text)
-
TruckSS = CDate(txtmTruckSS.Text)
-
TruckSE = CDate(txtmTruckSE.Text)
-
-
Try
-
Me.TrucksTableAdapter.Insert(Truckcode, TruckNo, TruckMake, TruckRegDate, TruckOption, TruckDriver, TruckTons, TruckSS, TruckSE)
-
Me.TrucksTableAdapter.Update(Me.UnkouTrucks.Trucks)
-
Catch ex As Exception
-
MsgBox("入力間違ってます 管理人にお問い合わせしてください....っていうかガヤンに聞いて" & ex.Message)
-
-
End Try
-
MsgBox("トラック1台追加されました", MsgBoxStyle.Information, "確認")
-
-
-
-
''**************** Update and Fill Truck Form **********************''
-
-
Try
-
-
Trucks.TrucksTableAdapter.Update(UnkouTrucks.Trucks)
-
Trucks.TrucksTableAdapter.Fill(UnkouTrucks.Trucks)
-
Catch ex As Exception
-
MsgBox("入力間違ってます 管理人にお問い合わせしてください....っていうかガヤンに聞いて" & ex.Message)
-
End Try
-
-
-
''**************** Clear The form for the next entry *****************''
-
ClearForm()
-
-
End Sub
Thank you
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".
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??!!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |