test

大范甘迪花粉管

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace SendOutRequire
{
    //连接数据库
    public class Connection
    {
        private static string connectionString =
            @"Server = 192.168.1.222;" +
            "Database = SendOutRequire;" +
            "User ID = SendOutRequire;" +
            "Password = sfj098()JIIfjskf09()()^&;";

        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <returns></returns>
        private SqlConnection ConnectionOpen()
        {
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            return conn;
        }

        /// <summary>
        /// 向外发日志表(SendOutLog)中插入一条数据
        /// </summary>
        /// <param name="fileName">文件名(含路径,例如:@"D:\U356test2.exe")</param>
        /// <param name="md5code">MD5码</param>
        /// <param name="ip"></param>
        /// <param name="dateTime"></param>
        public void Insert(string fileName, string md5code, string ip, DateTime dateTime)
        {
            SqlConnection conn = ConnectionOpen();
            string sql =
                "insert into SendOutLog (FileName, MD5, IP, DateTime) values ('" +
                fileName + "', '" + md5code + "', '" + ip + "', '" + dateTime + "')";
            SqlCommand comm = new SqlCommand(sql, conn);
            comm.ExecuteReader();
            conn.Close();
        }

        /// <summary>
        /// 从数据库中获取当前时间
        /// </summary>
        /// <returns></returns>
        public DateTime GetDateTimeFromSQL()
        {
            SqlConnection conn = ConnectionOpen();
            string sql = "select getdate()";
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlDataReader reader = comm.ExecuteReader();
            DateTime dt;
            if (reader.Read())
            {
                dt = (DateTime)reader[0];
                conn.Close();
                return dt;
            }
            conn.Close();
            return DateTime.MinValue;
        }
    }
}

 

posted @ 2014-05-06 10:16  疯人愿  阅读(77)  评论(0编辑  收藏  举报