三层架构:Helper层
public int count(string sql)
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=DB_class;User ID=sa;Pwd=123;");
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int num = (int)cmd.ExecuteScalar();
conn.Close();
return num;
}
public int count1(string sql)
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=DB_class;User ID=sa;Pwd=123;");
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
public DataTable count2(string sql)
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=DB_class;User ID=sa;Pwd=123;");
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter dr = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
dr.Fill(ds, "shopping");
DataTable dt = ds.Tables["shopping"];
return dt;
}