HELP! Select works but cannot write to the DB - SQL Express via C#

  • Thread starter Thread starter Lynn
  • Start date Start date
L

Lynn

HELP! And thanks for any thoughts in advance. :) I am writing in C#,
using a SQLExpress database. I am able to retrieve data without a
problem, but I cannot write to the DB. I don't get any error - but the
rows don't appear in the database! It is driving me nuts. There is no
error, no nothing!

Snippet below. Any thoughts at all appreciated.

private static string strConnect =
ConfigurationManager.ConnectionStrings["nmMyNamespace.Properties.Settin
gs.MyConnection_ConnectionString"].ConnectionString;

internal static System.Data.SqlClient.SqlConnection
objConnection = new System.Data.SqlClient.SqlConnection(strConnect);

objConnection.Open();

try
{
if (objConnection.State ==
System.Data.ConnectionState.Open)
{
objCmd = objConnection.CreateCommand();
objTrans =
objConnection.BeginTransaction("InsertRows");
objCmd.Connection = objConnection;
objCmd.Transaction = objTrans;
objCmd.CommandText = strInsertSQL;
objCmd.ExecuteNonQuery();
objTrans.Commit();
return true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top