ADO.net公共增删改查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class DBhelper
    {
        public static SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=库名;User ID=密码");
 
        //查询
        public SqlDataReader select(string sql)
        {
            SqlDataReader reader = null;
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            reader = comm.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            return reader;
        }
        //删除、添加、更改
        public static int ExecuteUpdate(string sql)
        {
            int result = 0;
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            result = comm.ExecuteNonQuery();
            conn.Close();
            return result;
        }
        //单条数据的查询
        public static Object ExecteOnlyOneVaule(string sql)
        {
            Object obj = null;
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            obj = comm.ExecuteScalar();
            conn.Close();
            return obj;
        }
    }

  

ADO.net公共增删改查,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。