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;
插入引用sql
1 public static string strconn = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
用於獲取連接字符串spa
public static DataTable Cha(string sql) { DataTable table = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(sql, strconn); sda.Fill(table); return table; }
用於查詢數據的方法code
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; }
用於增長新數據,刪除數據,修改數據blog