• 大小: 1.42MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: C#
  • 标签: 发送邮件  

资源简介

C# 先将从数据库中获取数据转成DataTable然后将DataTable生成excel,并将excel添加附件发送邮件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;

namespace SendMailDemo
{
    public class Conn
    {
        public static string StrConn
        {
            get
            {
                //读取文本文件(txt)
                //return Conn.getValue(@“C:\Users\Brambling\Desktop\Demo\SendMail\SendMail\DB_Config\DB_Config.txt“ “StrConn“);

                //读取配置文件
                //return ConfigurationManager.ConnectionStrings[“StrConn“].ToString();
                //return ConfigurationManager.AppSettings[“Conn“].ToString();

                //直接返回数据库连接字符串
                return “Data Source=.;Initial Catalog=TC_MES_WEB_ADMIN;User ID=sa;Pwd=jm123!@#;Enlist=true;Pooling=true;Max Pool Size=300;Min Pool Size=0;Connection Lifetime=300;packet size=1000“;
            }
        }

        public static SqlConnection SqlConn
        {
            get
            {
                return new SqlConnection(StrConn);
            }
        }

        private static string getValue(string path string name)
        {
            string[] str = File.ReadAllLines(path);
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i].StartsWith(name))
                {
                    return str[i].Replace(name + “=“ ““);
                }
            }
            return ““;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-18 16:21  SendMailDemo\
     目录           0  2018-04-18 16:21  SendMailDemo\.vs\
     目录           0  2018-04-18 16:21  SendMailDemo\.vs\SendMailDemo\
     目录           0  2018-04-18 16:21  SendMailDemo\.vs\SendMailDemo\v14\
     文件       43008  2018-04-18 21:18  SendMailDemo\.vs\SendMailDemo\v14\.suo
     目录           0  2018-04-18 22:11  SendMailDemo\SendMailDemo\
     文件        1003  2018-04-18 16:21  SendMailDemo\SendMailDemo.sln
     文件         189  2018-04-18 16:21  SendMailDemo\SendMailDemo\App.config
     目录           0  2018-04-18 16:21  SendMailDemo\SendMailDemo\bin\
     目录           0  2018-04-18 21:16  SendMailDemo\SendMailDemo\bin\Debug\
     文件     1602560  2014-06-26 06:40  SendMailDemo\SendMailDemo\bin\Debug\NPOI.dll
     文件      419840  2014-06-27 15:44  SendMailDemo\SendMailDemo\bin\Debug\NPOI.OOxml.dll
     文件      422053  2014-06-27 15:44  SendMailDemo\SendMailDemo\bin\Debug\NPOI.OOxml.xml
     文件       85504  2014-06-27 15:44  SendMailDemo\SendMailDemo\bin\Debug\NPOI.Openxml4Net.dll
     文件      153211  2014-06-27 15:44  SendMailDemo\SendMailDemo\bin\Debug\NPOI.Openxml4Net.xml
     文件     1869824  2014-06-27 15:44  SendMailDemo\SendMailDemo\bin\Debug\NPOI.OpenxmlFormats.dll
     文件       17408  2018-04-18 22:09  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.exe
     文件         189  2018-04-18 16:21  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.exe.config
     文件       32256  2018-04-18 22:09  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.pdb
     文件       22696  2018-04-18 22:11  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.vshost.exe
     文件         189  2018-04-18 16:21  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.vshost.exe.config
     文件         490  2015-10-22 09:54  SendMailDemo\SendMailDemo\bin\Debug\SendMailDemo.vshost.exe.manifest
     文件        1547  2018-04-18 16:52  SendMailDemo\SendMailDemo\Conn.cs
     文件       19026  2018-04-18 22:11  SendMailDemo\SendMailDemo\Form1.cs
     文件        2032  2018-04-18 16:23  SendMailDemo\SendMailDemo\Form1.Designer.cs
     文件        5817  2018-04-18 16:23  SendMailDemo\SendMailDemo\Form1.resx
     目录           0  2018-04-18 16:21  SendMailDemo\SendMailDemo\obj\
     目录           0  2018-04-18 21:28  SendMailDemo\SendMailDemo\obj\Debug\
     文件        1464  2018-04-18 20:43  SendMailDemo\SendMailDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7525  2018-04-18 21:16  SendMailDemo\SendMailDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         965  2018-04-18 22:11  SendMailDemo\SendMailDemo\obj\Debug\SendMailDemo.csproj.FileListAbsolute.txt
............此处省略19个文件信息

评论

共有 条评论