Hi,
I want to update the "read_status" colum when
reading data, this is my
way as below:
//
------------------------------------------------------------
-----------------------------------------
string strConn = "server=" + server +
";database=" + database + ";uid="
+ uid + ";pwd=" + pwd;
SqlConnection sqlConn = null;
SqlConnection updateConn = null;
try {
sqlConn = new SqlConnection(strConn);
sqlConn.Open();
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandTimeout = 10000000;
string sql = "Select id, name From member Where
read_status = 0";
sqlCmd.CommandText = sql;
SqlDataReader dataReader = sqlCmd.ExecuteReader();
updateConn = new SqlConnection(strConn);
updateConn.Open();
SqlCommand updateCmd = updateConn.CreateCommand();
updateCmd.CommandTimeout = 10000000;
while(dataReader.Read()){
// id
long id = Convert.ToInt64(dataReader["id"]);
string name = dataReader["name"].ToString();
// update read status
// * the application will stop to here *
updateCmd.CommandText = "Update member Set
read_status=1 Where id=" +
id;
updateCmd.ExecuteNonQuery();
}
}
catch(Exception exp) {
MessageBox.Show("Error:" + exp.Message,
"Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
} finally {
// close
if(sqlConn != null)
sqlConn.Close();
if(updateConn != null)
updateConn.Close();
}
//
------------------------------------------------------------
-----------------------------------------
When running the "update read status" line, the
app will be stopped.
What's the matter with my code? Thanks a lot.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|