I have a ms sql 2012 server and I use this function to add/records:
static String conString = "Provider=SQLOLEDB;Data Source = " + ecommerceServer + "; Initial Catalog = " + eCommercedbName + "; User Id = " + eCommerceUsername + "; Password = " + eCommercepassword + ";";
public bool InsertSQL(String query, String Tablename)
{
OleDbConnection conn = new OleDbConnection(conString);
try
{
conn.Open();
OleDbCommand command = new OleDbCommand(query, conn);
int count = command.ExecuteNonQuery();
return (count > 0) ? true : false;
}
catch
{
if (conn.State.ToString() == "Open")
{
conn.Close();
}
}
return false;
}
The function is quite slow (for example I have similar execution for MySQL and it workd much faster. Is there any faster ways than OleDb ?
Andrew below is an example of how you could you SQL Client as well as doing Transactions in your Query.. you can use this as a guide / learning example also replace the variables to fit your current example. also notice how I am reading my connection string from the app.config file if you do not need the Transactional code you can remove it.. but I believe it’s best to do things using transaction