C# - Insert Multiple Records to AS400

ovarma

New Member
I have a problem like this:
1. I retrieve data from MySQL using C# ASP .Net. -- done --
2. All data from no.1 will be inserted into table on AS400. -- I got an error on this step --

Error message says that \[code\]ERROR [42000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0104 - Token ; was not valid. Valid tokens: <END-OF-STATEMENT>.\[/code\]. It's true that I used semicolon to separate queries with each others, but it's not allowed. I've Googling but I can't find the solution.
My question is what the \[code\]<END-OF-STATEMENT>\[/code\] means of that error message..?
Here is my source code.
\[code\]private static void doInsertDOCADM(MySqlConnection conn) { // Get Temporary table String query = "SELECT * FROM TB_T_DOC_TEMPORARY_ADM"; DataTable dt = CSTDDBUtil.ExecuteQuery(query); OdbcConnection as400Con = null; as400Con = CSTDDBUtil.GetAS400Connection(); as400Con.Open(); if (dt != null && dt.Rows.Count > 0) { int counter = 1, maxInsertLoop = 50; using (OdbcCommand cmd = new OdbcCommand()) { cmd.Connection = as400Con; foreach (DataRow dr in dt.Rows) { cmd.CommandText += "INSERT INTO DCDLIB.WDFDOCQ VALUES " + "(?,?,?,?);"; cmd.Parameters.Add("1", OdbcType.VarChar).Value = http://stackoverflow.com/questions/12729267/dr["PROD_MONTH"].ToString(); cmd.Parameters.Add("2", OdbcType.VarChar).Value = http://stackoverflow.com/questions/12729267/dr["NEW_MAIN_DEALER_CD"].ToString(); cmd.Parameters.Add("3", OdbcType.VarChar).Value = http://stackoverflow.com/questions/12729267/dr["MODEL_SERIES"].ToString(); cmd.Parameters.Add("4", OdbcType.VarChar).Value = http://stackoverflow.com/questions/12729267/dr["MODEL_CD"].ToString(); if (counter < maxInsertLoop) { counter++; } else { counter = 1; cmd.ExecuteNonQuery(); cmd.CommandText = ""; cmd.Parameters.Clear(); } } if (counter > 1) cmd.ExecuteNonQuery(); } }\[/code\]Notes: I used this way (Collect some queries first, and then execute those query) to improve the performance of my application.
 
Back
Top