469,963 Members | 1,344 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

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 1557
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.

Similar topics

10 posts views Thread by Sugapablo | last post: by
2 posts views Thread by Robert Stearns | last post: by
1 post views Thread by Peter Newman | last post: by
10 posts views Thread by Phil Latio | last post: by
9 posts views Thread by Oonz | last post: by
4 posts views Thread by franc sutherland | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.