首页 新闻 搜索 专区 学院

SqlDataReader怎么转换为list类型,

0
悬赏园豆:30 [已解决问题] 解决于 2016-10-16 22:02

我从一个数据库中读取邮箱然后把邮箱账户转换为list

代码

  foreach (SCMQuoteSupplier supplier in quote.Suppliers)
            {
                
                string queryString = "SELECT cpEmail FROM [EAMDB].[dbo].[SupplierContactPerson] where supplierNo="+supplier.SupplierCode+";";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand(
                        queryString, connection);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                          
                           
                MailHelper.MailSending("报价通知", "有新的物料需要报价", "", "");
                        }
                    }
                    finally
                    {
                        // Always call Close when done reading.
                        reader.Close();
                    }
                }
               
            }

求帮助,小白一枚

我想和这个世界谈谈的主页 我想和这个世界谈谈 | 初学一级 | 园豆:61
提问于:2016-10-15 13:41
< >
分享
最佳答案
0

var list=new List<string>();

...

while(reader.Read())

{

 list.Add(reader["cpEmail"].ToString());

}

...

return list;

收获园豆:30
Daniel Cai | 专家六级 |园豆:10374 | 2016-10-16 00:13

 谢谢回答!

我想和这个世界谈谈 | 园豆:61 (初学一级) | 2016-10-16 22:02
其他回答(1)
0
 1 private IList<string> GetEmailAccount()
 2 {
 3     var accountList = new List<string>();
 4     foreach (SCMQuoteSupplier supplier in quote.Suppliers)
 5     {                
 6         string queryString = "SELECT cpEmail FROM [EAMDB].[dbo].[SupplierContactPerson] where supplierNo="+supplier.SupplierCode+";";
 7         using (SqlConnection connection = new SqlConnection(connectionString))
 8         {
 9             SqlCommand command = new SqlCommand(queryString, connection);
10             connection.Open();
11             SqlDataReader reader = command.ExecuteReader();
12             try
13             {
14                 while (reader.Read())
15                 {                        
16                     accountList.Add(reader["cpEmail"].ToString());                    
17                     MailHelper.MailSending("报价通知", "有新的物料需要报价", "", "");
18                 }
19             }
20             finally
21             {
22                 // Always call Close when done reading.
23                 reader.Close();
24             }
25         }            
26     }
27     return accountList;
28 }

 

Catcher8 | 园豆:364 (菜鸟二级) | 2016-10-16 17:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册