Я думаю, вы можете попытаться использовать cmd
только для select
и update
и удалить, если If(!reader.IsDBNull(1))
и переместить код update
во внешний цикл.
OleDbCommand cmd = null;
string queryString = "select email,status from tableemail";
using (OleDbConnection connection = new OleDbConnection("Provider = OraOLEDB.Oracle.1; Data Source = xe;
Password=eppspps;User ID = xpress; unicode=true"))
{
OleDbCommand command= new OleDbCommand(queryString, connection);
connection.Open();
cmd = new OleDbCommand(queryString);
cmd.Connection = connection;
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MailAddress to = new MailAddress(reader[0].ToString());
message.To.Add(to);
}
cmd.CommandText = " UPDATE tableemail set status=1 where status is null";
cmd.ExecuteNonQuery();
}
РЕДАКТИРОВАТЬ
Если вы хотите использовать update
в цикле while, вы можете попробовать использовать другой OleDbCommand
и выполнить обновление в if
string queryString = "select email,status from tableemail";
string updateString = "UPDATE tableemail set status=1 where email = @email";
using (OleDbConnection connection = new OleDbConnection("Provider = OraOLEDB.Oracle.1; Data Source = xe;
Password=eppspps;User ID = xpress; unicode=true"))
{
connection.Open();
OleDbCommand cmd = new OleDbCommand(queryString,Connection);
OleDbCommand cmd2 = new OleDbCommand(updateString,Connection);
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
MailAddress to = new MailAddress(reader[0].ToString());
message.To.Add(to);
if(!reader.IsDBNull(1)){
cmd2.Parameters.Clear();
cmd2.Parameters.Add(new OleDbParameter("email", reader["email"]));
cmd2.ExecuteNonQuery();
}
}
}