By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

error when inserting unique values

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.