1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Data; 6 using System.Data.SqlClient; 7 using System.Configuration;
插入引用
1 public static string strconn = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
用于获取链接字符串
public static DataTable Cha(string sql) { DataTable table = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(sql, strconn); sda.Fill(table); return table; }
用于查询数据的方法
public static int ZSG(string sql) { int num = 0; SqlConnection conn = new SqlConnection(strconn); SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); num = cmd.ExecuteNonQuery(); if (conn.State == ConnectionState.Open) { conn.Close(); } return num; }
用于增加新数据,删除数据,修改数据