I'm moving tables from a SQL Server DB to a MySQL DB programmatically.
I've got a SqlDataReader populated with a table's fields values, and I would like to insert them into the corresponding MySQL table. There aren't primary key and auto increment problems on destination table.
What I'm missing is howo to convert a SqlDataReader field value to a MySqlParameter value. This is a snippet of my code:
Cmd.CommandText = "SELECT a,b,c,d,e FROM sqlTable";
Cmd.Prepare();
dr = Cmd.ExecuteReader();
while (dr.Read())
{
MySqlConnection mySqlConn = new MySqlConnection(mySQLConnString);
mySqlConn.Open();
mySqlCmd.Connection = mySqlConn;
mySqlCmd.CommandText = "INSERT INTO mysqlTable VALUES (?, ?, ?, ?, ?) ";
for (int k = 0; k < dr.FieldCount; k++)
{
mySqlCmd.Parameters.Add(new MySqlParameter(dr[k].ToString(), dr[k]));
}
...
A fatal error occurs on the line, without any detail.
mySqlCmd.Parameters.Add(new MySqlParameter(dr[k].ToString(), dr[k]));
I cannot understand how to set dr[k]
value acceptable for MySQL.