error when inserting unique values

M

Muhammad Usman

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

Srini

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top