回复 3楼 乖老鼠
DBHelper.cs
private static string StrConn = ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
public static SqlConnection conn = new SqlConnection(StrConn);
---------------------------------------------------------------------------------------------------------------------------------------
AddFormDAL.cs
//封装
public void PrepareSQLCommand(string sql,SqlConnection conn,SqlCommand comm)
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
= sql;
comm.Connection = conn;
}
//增删改
public int ExecuteNonQuery(string str)
{
int count = 0;
using (SqlCommand comm = new SqlCommand())
{
PrepareSQLCommand(str, DBHelper.conn, comm);
count = comm.ExecuteNonQuery();
}
return count;
}