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

Insert Mutiple row into database

Hi all

I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e
I got this error:
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

Would you please tell me what to do to fix this problem?

Thanks
Nov 18 '05 #1
3 4312
Sorry my bad:
It should be like this

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message news:uA**************@tk2msftngp13.phx.gbl...
Hi all

I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e
I got this error:
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

Would you please tell me what to do to fix this problem?

Thanks
Nov 18 '05 #2
It looks like you have two rows that have the same primary key. Primary keys must be unique.
In your example it looks like your last row is conflicting with the row before it.
Try deleting the last row and see if that fixes it.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message news:uA**************@tk2msftngp13.phx.gbl...
Hi all

I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e
I got this error:
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

Would you please tell me what to do to fix this problem?

Thanks
Nov 18 '05 #3
Would you please take a lot at the code? It inserts into the table after the first try. When the 2nd time i comes back to insert it fails

PR) (PR)
ID Project Ans
1 2 a -> done
1 3 b -> fail here, program throws error
1 4 c
1 5 d


private void loadAnsToData(ArrayList myansList)

{

ArrayList qKeyList = storeQuestionKey();
string mystrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("dcpols.mdb");

OleDbConnection conn = new OleDbConnection(mystrConn);
string command = "Insert Into tblProjectData(PD_Proj_PKF,Q_PK,PD_Answer)"+

"Values (@projectID,@questionID,@answer)";

OleDbCommand myCommand = new OleDbCommand(command,conn);

myCommand.Connection.Open();

for (int i=0; i< qKeyList.Count;i++)

{

string answer = myansList[i].ToString();

string qKey = qKeyList[i].ToString();


OleDbParameter p1 = new OleDbParameter("@projectID",OleDbType.BigInt);

p1.Direction = ParameterDirection.Input;

p1.Value = Session["ProKey"];

myCommand.Parameters.Add(p1);

OleDbParameter p2 = new OleDbParameter("@projectID",OleDbType.BigInt);

p2.Direction = ParameterDirection.Input;

p2.Value = Convert.ToInt32(qKey);

myCommand.Parameters.Add(p2);

OleDbParameter p3 = new OleDbParameter("@projectID",OleDbType.VarChar);

p3.Direction = ParameterDirection.Input;

p3.Value = answer;

myCommand.Parameters.Add(p3);

myCommand.ExecuteNonQuery();

}

myCommand.Connection.Close();

}

"William Ryan" <do********@nospam.comcast.net> wrote in message news:u7****************@tk2msftngp13.phx.gbl...
How are you defining the DataRelation? With an Array of dataColumns?
http://www.knowdotnet.com/articles/datarelation.html

Where in the update is it failing? If it's failing on anything after (1,3)
then this isn't the problem, but let me see the DataRelation code...


"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:Os*************@TK2MSFTNGP12.phx.gbl...
Oh my bad
(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 6 e

I want it look like that but i fail when I loop to insert those rows in

the
database

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:Ox**************@TK2MSFTNGP11.phx.gbl...
Hi all

I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e
I got this error:
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
Would you please tell me what to do to fix this problem?

Thanks




"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message news:uA**************@tk2msftngp13.phx.gbl...
Hi all

I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field

(PR) (PR)
ID Project Ans
1 2 a
1 3 b
1 4 c
1 5 d
1 5 e
I got this error:
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

Would you please tell me what to do to fix this problem?

Thanks
Nov 18 '05 #4

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

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
4
by: topjun | last post by:
using osql to apply SPs in mutiple threads Hello, I got a weird problem when I was using osql to apply scripts for msde database in multiple threads mode. Sometime 2 sps were missing during the...
0
by: deepak | last post by:
i have set multiple selection property in bith listboxes(html control) to true. i have taken 2 buttons(html control) say Button1,Button2.now i want to add mutiple selected items to another listbox...
1
by: Irfan | last post by:
hi, I tried to google 'sql to insert multiple row MSaccess' but coudnt get a proper link. This is roughly what i want to do. .. I have Material, Load & filename as Columns in a table.All i...
0
by: saravana | last post by:
I have to display the mutiple xml filename path in treeview control using c#. net some thing like this In treeview control....... ========= =C:\\a.xml=
3
by: shanmugamit | last post by:
hi, i am new to this forum.i need help for view a mutiple selected value from database.....that is already selected value display.. my code..... $jobcount=count($vinloc); print" <td><select...
13
nabh4u
by: nabh4u | last post by:
hi, I am trying to insert multiple rows in a table using PL/SQL. I have two procedures and two tables. the first procedure gets the data from the source table, manipulates it and then sends the...
2
by: ravitunk | last post by:
hi..i have a datagridview in my windows application using C#......i want to select mutiple cells(by pressing shift key) or select mutiple columns or multiple rows.....if this happens then i should...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.