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

Prevent duplicate entry to MS Access database

I would like to know how to prevent entering the same data as a primary
key to an MS Access database and return with an error message
confirming the data already exists in ASP.Net (VB.Net).

Function AddFault(ByVal faultID As Integer, ByVal username As
String, ByVal title As String, ByVal desc As String) As Integer
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Documents an"& _
"d Settings\mazid\My Documents\Helpdesk\Helpdesk.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "INSERT INTO [Fault] ([FaultID],
[Username], [Title], [Desc]) VALUES (@FaultID, @U"& _
"sername, @Title, @Desc)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_faultID As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_faultID.ParameterName = "@FaultID"
dbParam_faultID.Value = faultID
dbParam_faultID.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_faultID)
Dim dbParam_username As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_username.ParameterName = "@Username"
dbParam_username.Value = username
dbParam_username.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_username)
Dim dbParam_title As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_title.ParameterName = "@Title"
dbParam_title.Value = title
dbParam_title.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_title)
Dim dbParam_desc As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_desc.ParameterName = "@Desc"
dbParam_desc.Value = desc
dbParam_desc.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_desc)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
End Function

Sub Page_Load(sender As Object, e As EventArgs)
If (Request.IsAuthenticated = true) Then
Username.Text = "User " & User.Identity.Name & " is currently
logged in."
End If
End Sub

Sub Submit_Click(sender As Object, e As EventArgs)
AddFault(faultID, Username.Text, txtTitle.Text, txtDesc.Text)
End Sub

in the above addfault I want to make sure that the faultID is not the
same for every fault. e.g. if user1 submits a faultID - 10001, the
next user should insert faultID 10002, the next user 10003 etc.

I would appreciate if anyone can assist in helping me complete some
code for scanning the database to scan for the same faultID.

Feb 8 '06 #1
0 1624

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

Similar topics

4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
2
by: eazyone | last post by:
I can prevent a duplicate ID from being entered, but can't figure out how to go to that specific record. I keep getting an error message on: Me.Bookmark = rsc.Bookmark Its not opening and...
5
by: Sheol | last post by:
Hello everyone! Can somebody please help me with this... I have a VB program that inputs Name and Address. I've made a database in MS Access using ADO Control: Table Name: Contacts Fields are:...
6
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger",...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
4
by: azura | last post by:
how i want to check if there is duplicate entry in my database?? i insert new record which is the same record that i had inserted before,it successfull insert into the database..i don't want that.....
1
by: Rocker1 | last post by:
Hello guys, I am reading a downloaded textfile which has a fields like date,NAV and Name using VB.NET. The date on which the textfile is downloaded remains the same.After each readline operation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
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: 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
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: 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 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.