1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Configuration;
6 using System.Data;
7 using System.Data.SqlClient;
插入引用
private static string strconn = ConfigurationManager.ConnectionStrings["DigitalProductShopConnectionString"].ConnectionString;
获取连接
1 public static DataTable ChaXun(string sql)
2 {
3 using (DataTable dt=new DataTable())
4 {
5 using (SqlDataAdapter sda=new SqlDataAdapter(sql,strconn))
6 {
7 sda.Fill(dt);
8 }
9
10 return dt;
11 }
12 }
查询方法
1 public static int FeiChaXun(string sql)
2 {
3 int i = 0;
4 using (SqlConnection conn = new SqlConnection(strconn))
5 {
6 using (SqlCommand scd = new SqlCommand(sql, conn))
7 {
8 try
9 {
10 conn.Open();
11 i = scd.ExecuteNonQuery();
12 }
13 finally
14 {
15 if (conn.State == ConnectionState.Open)
16 {
17 conn.Close();
18 }
19 }
20 }
21 }
22 return i;
23 }
增删改方法
来源:oschina
链接:https://my.oschina.net/u/4418565/blog/4316800