We are having problems with a bit of C# after upgrading to MSSQL 2008 (from MSSQL 2005 Express)
I have stripped out the un-required code to focus on the problem code.
C#/VB.NET Code:
DateTime shippedTime = DateTime.Now.AddDays(-5);
using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn())) {
dbconn.Open();
using (IDataReader rs = DB.GetRS(String.Format("select OrderNumber, FirstName, Email from Orders where ShippedOn < '{0}' and SentReviewEmail = 0", shippedTime.ToString("d",CultureInfo.CreateSpecificCulture("en-us"))))) {
int orderNu = 0;
while (rs.Read()) {
orderNu = rs.GetInt32(0);
// PROBLEM CODE
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "UPDATE Orders set SentReviewEmail = 1 WHERE OrderNumber = " + orderNu;
cmd.Connection = dbconn;
cmd.ExecuteNonQuery();
// END PROBLEM CODE
}}
dbconn.Close();
}
The code normally returns 20-30 orders and uses their ordernumber for finding out what products they brought and for updating we have sent them an email.
However the problem is this code that updates the database to say we have sent the email does not work. I have tested this script without the database update and the email works fine.
How can I update the database? Why does this code no longer work?
I have written the code in VS2008 and it shows no issues or problems.