Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Datagridview电子邮件(如果特定列包含某些文本)_C#_Visual Studio_Email_Datagridview - Fatal编程技术网

C# Datagridview电子邮件(如果特定列包含某些文本)

C# Datagridview电子邮件(如果特定列包含某些文本),c#,visual-studio,email,datagridview,C#,Visual Studio,Email,Datagridview,我有一个在搜索完成后填充在datagridview中的数据。我可以给名单上的人发电子邮件。我想添加一个语句来检查第25列中的特定文本(“1”),如果它找到了它,那么就添加这个收件人 谢谢你的帮助 Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.I

我有一个在搜索完成后填充在datagridview中的数据。我可以给名单上的人发电子邮件。我想添加一个语句来检查第25列中的特定文本(“1”),如果它找到了它,那么就添加这个收件人

谢谢你的帮助

            Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)
            outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[25].Value != null)
                {
                    if (dataGridView1.Rows[i].Cells[25].Value.ToString().Contains("1"))
                    {
                        mailItem.To = "test@test.com";
                    }                                            
                }
            }
            mailItem.To = string.Join(";", c1.Union(c2).Union(c3).Union(c4).ToArray());  

        }
        catch (Exception eX)
        {
            throw new Exception("cDocument: Error occurred trying to Create an Outlook Email"
                                + Environment.NewLine + eX.Message);
        }
Microsoft.Office.Interop.Outlook.Application outlookApp=new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem MailItem=(Microsoft.Office.Interop.Outlook.MailItem)
outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
对于(int i=0;i
试试看

  for(int i =0 ;i<dataGridView1.Rows.Count;i++)
        {
            if (dataGridView1.Rows[i].Cells[25].Value != null)
            {
                if (dataGridView1.Rows[i].Cells[25].Value.ToString().Contains("1"))
                {

                }
            }
        }
for(inti=0;i试试看

  for(int i =0 ;i<dataGridView1.Rows.Count;i++)
        {
            if (dataGridView1.Rows[i].Cells[25].Value != null)
            {
                if (dataGridView1.Rows[i].Cells[25].Value.ToString().Contains("1"))
                {

                }
            }
        }

for(int i=0;iI)尝试了此操作,但出现了一个catch错误…我将更新代码以便您可以看到它。我只是在最上面更新了代码..太长,无法在注释中输入。在cath…catch(Exception eX){throw new Exception(“cDocument:尝试创建Outlook电子邮件时出错”+Environment.NewLine+eX.Message);}我的意思是当调试器去捕获时?哪一行产生了异常?异常是在循环中发生的还是在mailTo中发生的?啊,明白了..我还是个新手。它发生在循环中。我尝试了,但我得到了一个捕获错误…我会更新代码以便你能看到它。我只是在最顶端更新了代码..太长了,无法进入到common中t、 在cath…catch(Exception eX){throw new Exception(“cDocument:尝试创建Outlook电子邮件时出错”+Environment.NewLine+eX.Message);}我的意思是当调试器去捕捉时?哪一行产生了异常?异常是在循环中发生的还是在mailTo中发生的?啊,明白了..我还是个新手。它发生在循环中。