我从一个数据库中读取邮箱然后把邮箱账户转换为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(); } } }
求帮助,小白一枚
var list=new List<string>();
...
while(reader.Read())
{
list.Add(reader["cpEmail"].ToString());
}
...
return list;
谢谢回答!
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 }