zoukankan      html  css  js  c++  java
  • C#实现人脸识别【SqlHelper】

    操作数据库工具类:

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Data;
    
    namespace face
    {
        /// <summary>
        /// 数据库工具类
        /// </summary>
        public class SqlHelper
        {
            #region 获取数据库连接
            private static string GetConnectionString
            {
                get
                {
                    return "Data Source=.;Initial Catalog=TestFaceDB;Persist Security Info=True;User ID=sa;Password=171268"; //转换成string类型
                }
            }
            #endregion
    
            #region 查询多条记录
            /// <summary>
            /// 查询多条记录
            /// params SqlParameter  param  表示既可以传过来数组  也可以传过来单个值
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="type"></param>
            /// <param name="param"></param>
            /// <returns></returns>
            public static SqlDataReader ExcuteReader(string sql, CommandType type, params SqlParameter[] param)
            {
                SqlConnection conn = new SqlConnection(GetConnectionString);
                SqlCommand cmd = new SqlCommand(sql, conn);
                PreaPareCommand(sql, conn, cmd, type, param);
                //参数是关闭连接
                return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            #endregion
    
    
            #region DataSet
            public static DataSet ExexuteDataset(string sql, CommandType type, params SqlParameter[] param)
            {
                using (SqlConnection conn = new SqlConnection(GetConnectionString))
                {
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    PreaPareCommand(sql, conn, cmd, type, param);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    sda.Fill(ds);
                    return ds;
                }
            }
            #endregion
    
    
            #region 查询返回一条记录
            /// <summary>
            /// 查询返回一条记录
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="type"></param>
            /// <param name="param"></param>
            /// <returns></returns>
            public static Object ExecuteScalar(string sql, CommandType type, params SqlParameter[] param)
            {
                using (SqlConnection conn = new SqlConnection(GetConnectionString))
                {
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    PreaPareCommand(sql, conn, cmd, type, param);
                    return cmd.ExecuteScalar();
                }
            }
            #endregion
    
            #region 命令对象装配
            //命令对象装配
            private static void PreaPareCommand(string sql, SqlConnection conn, SqlCommand cmd, CommandType type, params SqlParameter[] param)
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Close();
                    conn.Open();
                }
                cmd.CommandType = type;
                if (param != null)
                {
                    foreach (SqlParameter p in param)
                    {
                        cmd.Parameters.Add(p);
                    }
                }
            }
            #endregion
    
            #region 增删改
            public static int ExecuteNonQuery(string sql, CommandType type, params SqlParameter[] param)
            {
                using (SqlConnection conn = new SqlConnection(GetConnectionString))
                {
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    PreaPareCommand(sql, conn, cmd, type, param);
                    return cmd.ExecuteNonQuery();
                }
            }
            #endregion
    
        }
    }
    
  • 相关阅读:
    web基础要点记录
    前端一些干货
    正则表达式手册
    JQuery实现旋转轮播图
    JQuery模拟常见的拖拽验证
    electron应用以管理员权限启动
    原生JS模拟百度搜索关键字与跳转
    关于Application的使用
    Android事件分发机制(相关文章)
    (转)Activity的四种launchMode
  • 原文地址:https://www.cnblogs.com/a1111/p/12816128.html
Copyright © 2011-2022 走看看