数据库操作类
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System.Data.SqlClient;
public class DataConn
{
public DataConn() { }
public static string strconn =
ConfigurationManager.ConnectionStrings["xsconstr"].ConnectionString;
public static SqlConnection CreateConn()
{
SqlConnection conn = new SqlConnection(strconn);
return conn;
}
public static SqlDataReader ExecuterRead(string cmdtext, SqlConnection conn)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
mandText = cmdtext;
SqlDataReader dr = cmd.ExecuteReader();
return dr;
}
public static SqlDataReader ExecuterRead(string cmdtext, SqlConnection conn, params SqlParameter[] array1)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
mandText = cmdtext;
foreach (SqlParameter para in array1)
cmd.Parameters.Add(para);
SqlDataReader dr = cmd.ExecuteReader();
return dr;
}
public static int ExecuteNonRead(string cmdtext)
{
SqlConnection conn = CreateConn();
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
public static int ExecuteNonRead(string cmdtext, params SqlParameter[] array)
{
SqlConnection conn = CreateConn();
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
foreach (SqlParameter para in array)
cmd.Parameters.Add(para);
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
public static object ExecuteQueryValue(string cmdtext, params SqlParameter[] array)
{
SqlConnection conn = CreateConn();
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
foreach (SqlParameter para in array)
cmd.Parameters.Add(para);
object o = cmd.ExecuteScalar();
conn.Close();
return o;
}
public static object ExecuteQueryValue(string cmdtext)
{
SqlConnection conn = CreateConn();
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
object o = cmd.ExecuteScalar();
conn.Close();
return o;
}
public static DataSet ExecuteReturnDataSet(string cmdtext, params SqlParameter[] array) {
SqlConnection conn = CreateConn();
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
foreach (SqlParameter para in array)
cmd.Parameters.Add(para);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds=new DataSet ();
adapter.Fill(ds);
conn.Close();
return ds;
}
public static DataTable ExecuteReturnDataTable(string cmdtext, params SqlParameter[] array)
{
SqlConnection conn = CreateConn();