Well, that is frought with danger because a) you're relying on the data in rdr to always be there, and b) You're not using parameterized queries. I would do something like this (caution - this is untested code, so I might have gotten some stuff wrong):
using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM dbSchema", con))
{
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
string tablename;
int columns;
try
{
tablename = rdr.GetString("TableName");
columns = rdr.GetInt32("Columns");
string newQuery = "INSERT INTO DestDB.@tablename (Columns) Values(@columns);";
string newQuery2 = "SELECT [Columns] FROM SourceDB.@tablename";
SQLiteCommand cmd = new SQLiteCommand(newQuery, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("@tablename", tablename));
cmd.Parameters.Add(new SqlParameter("@columns", columns));
cmd.ExceuteNonQuery();
cmd.CommandText = newQuery2;
using (SqliteDataReader rdr2 = cmd.ExecuteReader())
{
while (rdr.Read())
{
}
}
}
catch (Exception ex)
{
}
}
}
}
FWIW, you don't have to re-query the database to see if the data was added to the table. All you have to do is see if the number of rows changed is equal to 1 (the return value from
ExecuteNonQuery
).