I have create the following insert method by researching the internet but I know it needs some work since it quite bulky and unsightly. I have tested it and it works fairly well but I know it could work better. If possible could someone show me how to convert this method to use parameters and/or increase its efficency?
public static void SQLiteTableINSERT(string tableName)
{
int colCount = 0;
using (SQLiteConnection Conn = new SQLiteConnection(SQLiteConn.Conn))
{
using (SQLiteTransaction sqliteTrans = Conn.BeginTransaction())
{
using (SQLiteCommand cmd = Conn.CreateCommand())
{
DataTableColumnNames();
string query = "INSERT INTO " + tableName + "(";
foreach (string name in DtColumns)
{
query += "[" + name + "]";
++colCount;
if (colCount < DtColumns.Count())
query += ",";
}
query += ")";
query += " VALUES(";
for (int i = 0; i < LocalDataSet.LocalDs.Tables[0].Rows.Count; ++i)
{
cmd.CommandText = query;
foreach (DataColumn col in LocalDataSet.LocalDs.Tables[0].Columns)
{
string temp = LocalDataSet.LocalDs.Tables[0].Rows[i][col, DataRowVersion.Current].ToString();
if (temp == "True")
cmd.CommandText += 1;
else if (temp == "")
cmd.CommandText += 0;
if (temp != "True" && temp != "")
cmd.CommandText += "'" +temp + "'";
cmd.CommandText += ",";
}
cmd.CommandText = cmd.CommandText.Remove(cmd.CommandText.LastIndexOf(","));
cmd.CommandText += ")";
cmd.ExecuteNonQuery();
}
}
sqliteTrans.Commit();
}
}
}
Thanks, Nathan