Page 1 of 1

Tutorial C# Bulk inserts

Posted: Sun 20 May 2012 15:52
by onwww.org
#1 Thank you for a great product
#2 I have had difficultly setting up the product.
I understand that you supply your product for developers, but if you target young developers maybe you will get more usage.

I am attempting to insert from a foreach loop into the database

In the example you gave in the help file

using Devart.Data.SQLite;
try
{
SQLiteConnection conn = new SQLiteConnection("Data Source=MainDataBase.db");
SQLiteCommand cmd = new SQLiteCommand();
conn.Open();
var insertSQL = new SQLiteCommand("INSERT INTO ValuesTBL (Value1,DateAdded) VALUES (@uNavnParam, @bNavnParam)", conn);
insertSQL.Parameters.AddWithValue("@uNavnParam", val1org);
insertSQL.Parameters.AddWithValue("@bNavnParam", val1org);
insertSQL.ExecuteNonQuery(); //Exe
//cmd.CommandText = "INSERT INTO ValuesTBL (Value1,DateAdded) VALUES (?, ?)";
//cmd.Parameters.Add("param1", val1org);
//cmd.Parameters.Add("param2", DateTime.Now.ToString());
//cmd.Connection = conn;
conn.Open();
try
{
//// MessageBox.Show();
// int aff = cmd.ExecuteNonQuery();
// MessageBox.Show(aff + " rows were affected.");
}
catch (Exception ex)
{
DataLogEntry("Application Error", ex.ToString());
MessageBox.Show("Error encountered during INSERT operation.");
throw new Exception();
}
finally
{
conn.Close();
}
in the trace the query remains INSERT INTO ValuesTBL (Value1,DateAdded) VALUES (?, ?)
http://www.devart.com/dotconnect/sqlite ... eters.html
so I named the parameters and now the sql file is locked

Re: Tutorial C# Bulk inserts

Posted: Thu 24 May 2012 13:49
by Pinturiccio
onwww.org wrote:I am attempting to insert from a foreach loop into the database
Could you please post the code with the foreach loop or send us a test project with the corresponding database?
onwww.org wrote:so I named the parameters and now the sql file is locked.
Could you please specify what you mean by saying "sql file", what it is locked by, and for how long it is locked?

The snippet of code where you use the named and unnamed parameters works correctly. The database file is locked because the connection is present in the pool: http://www.devart.com/dotconnect/sqlite ... Q.html#q52
Could you please state your question more accurately, as we couldn't get from your post what exactly worked wrong or what was your question.