the insert s successful, but nothing changes in DB!

G

Guest

Hey, this code seems to work fine,

since there is no rows in the DB, it does the INSERT statement. then it
proceeds to the second update statement and works great. but nothing is
actually inserted into the database. its sql 2005, and this is .net 2.0 in
C#.

any ideas?

P.S. I have windows authentication, and SQL authentication.

public static bool UpdateLoggingOptionsTab(int WriteToLogs, string
SMTPServerName, bool SMTPUseAuthentication, string SMTPUserName, string
SMTPPassword, string EmailSenderAddress, string NotificationEmailAddress1,
string NotificationEmailAddress2, string NotificationEmailAddress3, bool
NotifyInformationEvents, bool NotifyErrorEvents, bool NotifyWarningEvents,
bool NotifyCriticalErrorEvents, bool NotifyFatalErrorEvents)
{
try
{
SqlCon = new
SqlConnection(Aldelo.FI.Client.GlobalVariables.ConString);
SqlCmd = new SqlCommand("SELECT SMTPServerName, SMTPUSERNAME,
SMTPUSEAUTHENTICATION, SMTPUSERPASSWORD, EMAILSENDERADDRESS,
NOTIFICATIONEMAILADDRESS1, NOTIFICATIONEMAILADDRESS2,
NOTIFICATIONEMAILADDRESS3, NOTIFYINFORMATIONEVENTS, NOTIFYERROREVENTS,
NOTIFYWARNINGEVENTS, NOTIFYFATALERROREVENTS FROM NOTIFICATION", SqlCon);

SqlCon.Open();
SqlDr = SqlCmd.ExecuteReader();

if (SqlDr.HasRows)
{
SqlCon.Close();
SqlCon.Open();
SqlCmd1 = new SqlCommand("UPDATE NOTIFICATION SET SMTPSERVERNAME
= '" + SMTPServerName + "', SMTPUSEAUTHENTICATION = '" +
SMTPUseAuthentication + ", SMTPUSERNAME = '" + SMTPUserName + "',
SMTPUSERPASSWORD = '" + SMTPPassword + "', EMAILSENDERADDRESS = '" +
EmailSenderAddress + "', NOTIFICATIONEMAILADDRESS1 = '" +
NotificationEmailAddress1 + "', NOTIFICATIONEMAILADDRESS2 = '" +
NotificationEmailAddress2 + "', NOTIFICATIONEMAILADDRESS3 = '" +
NotificationEmailAddress3 + "', NOTIFYINFORMATIONEVENTS = '" +
NotifyInformationEvents + "', NOTIFYERROREVENTS = '" + NotifyErrorEvents +
"', NOTIFYWARNINGEVENTS = '" + NotifyWarningEvents + "',
NOTIFYCRTICIALERROREVENTS = '" + NotifyCriticalErrorEvents + "',
NOTIFYFATALERROREVENTS = '" + NotifyFatalErrorEvents + "'", SqlCon);
SqlCmd1.ExecuteNonQuery();
}
else
{
SqlCon.Close();
SqlCon.Open();
SqlCmd1 = new SqlCommand("INSERT INTO
NOTIFICATION(SMTPServerName, SMTPUSEAUTHENTICATION, SMTPUSERNAME,
SMTPUSERPASSWORD, EMAILSENDERADDRESS, NOTIFICATIONEMAILADDRESS1,
NOTIFICATIONEMAILADDRESS2, NOTIFICATIONEMAILADDRESS3,
NOTIFYINFORMATIONEVENTS, NOTIFYERROREVENTS, NOTIFYWARNINGEVENTS,
NOTIFYCRITICALERROREVENTS, NOTIFYFATALERROREVENTS) VALUES( '" +
SMTPServerName + "','" + SMTPUseAuthentication + "','" + SMTPUserName +
"','" + SMTPPassword + "','" + EmailSenderAddress + "','" +
NotificationEmailAddress1 + "','" + NotificationEmailAddress2 + "','" +
NotificationEmailAddress3 + "','" + NotifyInformationEvents + "','" +
NotifyErrorEvents + "','" + NotifyWarningEvents + "','" +
NotifyCriticalErrorEvents +"','" + NotifyFatalErrorEvents + "')", SqlCon);
SqlCmd1.ExecuteNonQuery();

}

SqlCon.Close();

SqlCmd2 = new SqlCommand("UPDATE STORESETTING SET WRITETOLOG= " +
WriteToLogs, SqlCon);
SqlCon.Open();
SqlCmd2.ExecuteNonQuery();
SqlCon.Close();

return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);

}
 
G

Guest

hmm... nevermind.. now it DOES add to the database, and updates too... very
strange. O well.
thanks guys. lol.
 

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

Top