SQL datareader读取不一致

时间:2015-08-26 13:15:29

标签: c# sql sqldatareader

我在C#中有以下代码 -

private void sendnotificationmail(string enqid)
{
    try
    {
        connection.Open();
        List<string> maillist = new List<string>();
        string sql = "SELECT     TrussLog.repmail, TrussLog.branchemail, TrussEnquiry.DesignerEmail FROM         TrussLog FULL OUTER JOIN                      TrussEnquiry ON TrussLog.enquirynum = TrussEnquiry.Enquiry_ID         where TrussEnquiry.Enquiry_ID = '" + enqid + "'";
        SqlCommand cmd = new SqlCommand(sql);
        SqlDataReader reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            if (!string.IsNullOrEmpty(reader[0].ToString()))
            {
                maillist.Add(reader[0].ToString());
            }
            if (!string.IsNullOrEmpty(reader[1].ToString()))
            {
                maillist.Add(reader[1].ToString());
            }
            if (!string.IsNullOrEmpty(reader[2].ToString()))
            {
                maillist.Add(reader[2].ToString());
            }
        }
        connection.Close();

        if (result != DialogResult.Cancel)
        {
            processmail(maillist);
        }
    }
    catch (Exception)
    {
    }
}

我从Windows窗体上的组合框中获取变量enqid的值。组合框的内容从数据库中检索。在表单加载时,组合框显示从数据库中检索的第一个enquiryID。当我运行程序时,数据读取器会跳过循环。但是,如果我在组合框中选择不同的查询,则数据阅读器正常工作

0 个答案:

没有答案