473,549 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error when inserting unique values

hi,

I have a table of student which contain four fields that
are id(primary key number) , name(text),seme ster(text)and
corse(text), When I insert values in a student
table.Explorer Show the follwing exception string.

"The changes you requested to the table were not
successful because they would create duplicate values in
the index, primary key, or relationship. Change the data
in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate
entries and try again."

I am using different values in the code that are not
already exist in table.

The code for insertion is given below.

try
{
OleDbConnection con=new
OleDbConnection (@"provider=mic rosoft.jet.oled b.4.0 ; data
source=D:\Inetp ub\wwwroot\ado_ net\test.mdb");
string isql="INSERT INTO
student VALUES(14,'sam' ,'4th','ACCP')" ;
OleDbCommand ins=new
OleDbCommand(is ql,con);
ins.Connection. Open();
ins.ExecuteNonQ uery();
ins.Connection. Close();
}
catch(Exception ec)
{
Response.Write
(ec.Message.ToS tring());
}
Please solve my problem, i am using c# as code behind.
Thanks

Muhammad Usman.
Nov 17 '05 #1
1 1675
What is the hardcoded 14 . Check in the database if a 14
already exists in the database or not. I think if you
change the database field as type auto it should suffice
your purpose.
-----Original Message-----
hi,

I have a table of student which contain four fields that
are id(primary key number) , name(text),seme ster(text)and
corse(text), When I insert values in a student
table.Explor er Show the follwing exception string.

"The changes you requested to the table were not
successful because they would create duplicate values in
the index, primary key, or relationship. Change the data
in the field or fields that contain duplicate data, removethe index, or redefine the index to permit duplicate
entries and try again."

I am using different values in the code that are not
already exist in table.

The code for insertion is given below.

try
{
OleDbConnection con=new
OleDbConnectio n(@"provider=mi crosoft.jet.ole db.4.0 ; data
source=D:\Inet pub\wwwroot\ado _net\test.mdb") ;
string isql="INSERT INTO
student VALUES(14,'sam' ,'4th','ACCP')" ;
OleDbCommand ins=new
OleDbCommand(i sql,con);
ins.Connection. Open();
ins.ExecuteNonQ uery();
ins.Connection. Close();
}
catch(Exception ec)
{
Response.Write
(ec.Message.To String());
}
Please solve my problem, i am using c# as code behind.
Thanks

Muhammad Usman.
.

Nov 17 '05 #2

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

Similar topics

10
41934
by: Sugapablo | last post by:
Let's say I create a new record in a table like this: mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn); ....that had an auto-incrementing, unique identifying column named "ID" that would be populated with a unique number upon insertion... How can I get the unique number it assigned to that record returned for futher use?
2
7623
by: Robert Stearns | last post by:
I don't understand the reference "2" in the following message. There is only a primary key constraint on the named table. It is generated by default and Im not inserting a value for it. SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary...
4
2096
by: frank | last post by:
I posted a question before (to too many groups) and this time I am sending to this group only. I have a quick script as seen below, the file_list table has a unique field called file_name. The problem I am having is that if no unique items exist, this will insert into the table fine. But if a unique item does exist it will not insert as it...
2
9426
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from prod400db.test.meldbf.InventoryHistory However, this insert statement fails: insert into prod400db.TEST.MELDBF.InventoryHistory
1
3708
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO CREATE TABLE dbo.aTable ( INT NOT NULL
1
1034
by: Peter Newman | last post by:
when I load a form I create a dateaset using (part of sub ) Orig_Accounts = GetSQLDataSet("EXEC BossData.dbo.SQL2005_ORIGACCOUNTS", "TBL_OrigAccounts") ' Set Primary Keys SearchKey(0) = Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_Licence") SearchKey(1) = Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_AccountID")...
10
3224
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I capture this specific error? Would it make more sense to actually run a SELECT query first and if that returned a result, then I use that for...
9
6926
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
4
7589
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to an excel spreadsheet. There are two tables. One is a list of general contacts, and the other is a list of clubs. The clubs contain members who...
0
7541
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
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 we have to send another system
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.