G
gloria
I get a strange error when working with a dataset. I can fill the
dataset and assign it to a table. I get the count. However, when I
try to insert the rows from the dataset to another table I get the
following error: "Error Inserting: The connection is already Open
(state=Open)."
I moved my open and close and even commented them out. But I still get
errors: "Error Inserting: ExecuteReader requires an open and available
Connection. The connection's current state is Closed."
What am I doing wrong? I think I've tried all possible combinations of
open/close, but I'm obviously missing at least one.
Thanks!
--gloria
OleDbConnection loadnewpartsCN = new
OleDbConnection(newpartsClass.strConn);
OleDbDataAdapter newpartsqueryDA = new
OleDbDataAdapter(newpartsqueryStr,loadnewpartsCN);
DataSet newpartsqueryDS = new DataSet();
Console.WriteLine("Filling dataset...");
newpartsqueryDA.Fill(newpartsqueryDS);
Console.WriteLine("Dataset filled.");
string partnum, desc, serializedflag, status, hscode, coo;
int serializedint;
DataTable table888 = newpartsqueryDS.Tables[0];
int rowcnt = table888.Rows.Count;
Console.WriteLine("Row Cnt: " + rowcnt);
//loadnewpartsCN.Open();
foreach(DataRow row888 in table888.Rows)
{
partnum = row888["PartNumber"].ToString();
desc = row888["PartDescription"].ToString();
serializedflag = row888["Serialized"].ToString();
status = row888["Status"].ToString();
hscode = row888["HS_Code"].ToString();
coo = row888["COO"].ToString();
if (serializedflag == "False")
serializedint = 0;
else
serializedint = 1;
string insertnewpartsStr = "insert into table_BAXPartsMaster " +
"values(" + newpartsClass.reg_subinv + ",'" + partnum + "','" + desc +
"',"
+ serializedint + ",'" + status + "','" + hscode + "','" +
coo + "'," + "1," + " NULL," + " NULL," + " 'I'," + " 0," +
" getdate()," + " getdate()," + " NULL);" +
"insert into table_BAXPartsMaster " +
"values(" + newpartsClass.fis_subinv + ",'" + partnum + "','" + desc +
"',"
+ serializedint + ",'" + status + "','" + hscode + "','" +
coo + "'," + "1," + " NULL," + " NULL," + " 'I'," + " 0," +
" getdate()," + " getdate()," + " NULL)";
try
{
OleDbCommand insertnewpartsCmd = new
OleDbCommand(insertnewpartsStr,loadnewpartsCN);
OleDbDataReader insertnewpartsRdr = insertnewpartsCmd.ExecuteReader();
}
catch (Exception ex2)
{
Console.WriteLine("Error Inserting: " + ex2.Message);
}
}
//loadnewpartsCN.Close();
dataset and assign it to a table. I get the count. However, when I
try to insert the rows from the dataset to another table I get the
following error: "Error Inserting: The connection is already Open
(state=Open)."
I moved my open and close and even commented them out. But I still get
errors: "Error Inserting: ExecuteReader requires an open and available
Connection. The connection's current state is Closed."
What am I doing wrong? I think I've tried all possible combinations of
open/close, but I'm obviously missing at least one.
Thanks!
--gloria
OleDbConnection loadnewpartsCN = new
OleDbConnection(newpartsClass.strConn);
OleDbDataAdapter newpartsqueryDA = new
OleDbDataAdapter(newpartsqueryStr,loadnewpartsCN);
DataSet newpartsqueryDS = new DataSet();
Console.WriteLine("Filling dataset...");
newpartsqueryDA.Fill(newpartsqueryDS);
Console.WriteLine("Dataset filled.");
string partnum, desc, serializedflag, status, hscode, coo;
int serializedint;
DataTable table888 = newpartsqueryDS.Tables[0];
int rowcnt = table888.Rows.Count;
Console.WriteLine("Row Cnt: " + rowcnt);
//loadnewpartsCN.Open();
foreach(DataRow row888 in table888.Rows)
{
partnum = row888["PartNumber"].ToString();
desc = row888["PartDescription"].ToString();
serializedflag = row888["Serialized"].ToString();
status = row888["Status"].ToString();
hscode = row888["HS_Code"].ToString();
coo = row888["COO"].ToString();
if (serializedflag == "False")
serializedint = 0;
else
serializedint = 1;
string insertnewpartsStr = "insert into table_BAXPartsMaster " +
"values(" + newpartsClass.reg_subinv + ",'" + partnum + "','" + desc +
"',"
+ serializedint + ",'" + status + "','" + hscode + "','" +
coo + "'," + "1," + " NULL," + " NULL," + " 'I'," + " 0," +
" getdate()," + " getdate()," + " NULL);" +
"insert into table_BAXPartsMaster " +
"values(" + newpartsClass.fis_subinv + ",'" + partnum + "','" + desc +
"',"
+ serializedint + ",'" + status + "','" + hscode + "','" +
coo + "'," + "1," + " NULL," + " NULL," + " 'I'," + " 0," +
" getdate()," + " getdate()," + " NULL)";
try
{
OleDbCommand insertnewpartsCmd = new
OleDbCommand(insertnewpartsStr,loadnewpartsCN);
OleDbDataReader insertnewpartsRdr = insertnewpartsCmd.ExecuteReader();
}
catch (Exception ex2)
{
Console.WriteLine("Error Inserting: " + ex2.Message);
}
}
//loadnewpartsCN.Close();