By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

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

P: n/a
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;
}
}

Jan 30 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
FAQ for "My database isn't being updated, but no errors occurred in my
application"
http://forums.microsoft.com:80/MSDN/...27451&SiteID=1
Robin S.
--------------------------
"Lynn" <El******@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
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;
}
}

Jan 31 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.