我有这种方法,它必须连续扫描数据库表 Announce,直到出现新记录,它将它与另一个表中的记录进行比较,如果匹配,则从表中删除它Announce 并继续搜索,直到出现另一个记录。有没有更好的方法来代替使用 while(true) 语句。注意:我使用的是 Sqlserver
//Begin method
public void Begin()
{
string announce;
double announceID;
try
{
using (SqlConnection connStr = new SqlConnection(ConfigurationManager.ConnectionStrings["AnnounceConnString"].ConnectionString))
{
while (true)
{
//Selects Last record written to tblAnnounce
SqlCommand sqlcommandStart = new SqlCommand("AnnounceSelect", connStr);
sqlcommandStart.CommandType = CommandType.StoredProcedure;
connStr.Open();
SqlDataReader dr = sqlcommandStart.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
announce = dr["AnnounceID"].ToString();
announceID = Convert.ToDouble(announce);
//Compares Values
//if it matches then DELETE record from TblAnnounce
}
connStr.Close();
}
else
{
connStr.Close();
}
dr.Close();
}
}
}
catch(Exception ex)
{
string exception = ex.Message;
MessageBox.Show(exception
}
}