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