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

error when inserting unique values

hi,

I have a table of student which contain four fields that
are id(primary key number) , name(text),semester(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=microsoft.jet.oledb.4.0 ; data
source=D:\Inetpub\wwwroot\ado_net\test.mdb");
string isql="INSERT INTO
student VALUES(14,'sam','4th','ACCP')";
OleDbCommand ins=new
OleDbCommand(isql,con);
ins.Connection.Open();
ins.ExecuteNonQuery();
ins.Connection.Close();
}
catch(Exception ec)
{
Response.Write
(ec.Message.ToString());
}
Please solve my problem, i am using c# as code behind.
Thanks

Muhammad Usman.
Nov 17 '05 #1
1 1670
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),semester(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, 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
OleDbConnection(@"provider=microsoft.jet.oledb.4. 0 ; data
source=D:\Inetpub\wwwroot\ado_net\test.mdb");
string isql="INSERT INTO
student VALUES(14,'sam','4th','ACCP')";
OleDbCommand ins=new
OleDbCommand(isql,con);
ins.Connection.Open();
ins.ExecuteNonQuery();
ins.Connection.Close();
}
catch(Exception ec)
{
Response.Write
(ec.Message.ToString());
}
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
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"...
2
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...
4
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...
2
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...
1
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...
1
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) =...
10
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...
9
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
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...
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
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
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
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,...
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...
0
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...

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.