数据库操作类(万能)
using System.Data;
using System.Data.SqlClient;
class connect
{
public string cmdstr { get; set; }
public string soure { get; set; }
public connect(string strcmd,string database,out int i,params string[] arry)
{
cmdstr = strcmd;
soure = "server=(local);database="+database+";trusted_connection=true";
SqlConnection con = new SqlConnection(soure);
con.Open();
SqlCommand cmd = new SqlCommand(cmdstr,con);
for (int a = 0;a < arry.Length; a++)
{
cmd.Parameters.Add("@"+a,arry[a]);
}
i = cmd.ExecuteNonQuery();
}
public connect(string strcmd, string database, out SqlDataAdapter dataadapter, params string[] arry)
{
cmdstr = strcmd;
soure = "server=(local);database=" + database + ";trusted_connection=true";
SqlConnection con = new SqlConnection(soure);
con.Open();
dataadapter = new SqlDataAdapter(strcmd,con);
for (int a = 0; a < arry.Length; a++)
{
dataadapter.SelectCommand.Parameters.Add("@"+a,arry[a]);
}
}
public connect(string strcmd, string database, out SqlDataReader reader, params string[] arry)
{
cmdstr = strcmd;
soure = "server=(local);database=" + database + ";trusted_connection=true";
SqlConnection con = new SqlConnection(soure);
con.Open();
SqlCommand cmd = new SqlCommand(cmdstr,con);
for (int a = 0; a < arry.Length; a++)
{
cmd.Parameters.Add("@" + a, arry[a]);
}
reader = cmd.ExecuteReader();
}
}