ADO 数据库连接基础

 

        /// <summary>
        /// 数据库查询并返回结果集
        /// </summary>
        /// <param name="_sql">需要执行的SQL语句或者存储过程名称</param>
        /// <param name="_type">命令类型,text/StoredProcedure/TableDirect</param>
        /// <param name="_constring">数据库连接</param>
        /// <param name="_parameter">参数</param>
        /// <returns></returns>
        public DataSet SqlExecuteReader(string _sql, CommandType _type, string _constring, SqlParameter _parameter)
        {
            DataSet ds = new DataSet();
            try
            {
                using (SqlConnection conn = new SqlConnection(_constring))
                {
                    SqlCommand cmd = new SqlCommand(_sql, conn);
                    // cmd.Parameters.Add(_parameter);
                    cmd.CommandType = _type;
                    cmd.CommandTimeout = _timeout;//超时时间,单位S
                    conn.Open();
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(ds);//填充dataset
                    }
                }
                return ds;
            }
            catch (Exception ex)
            {
                throw;
            }

cmd.ExecuteNonQuery()//是返回受影响的行数

上一篇:I2C通信基本原理及其实现


下一篇:STM32学习笔记---IIC协议