private const string sql = "Data Source=.;Initial Catalog=auto;User=sa;Pwd=sasa";
SqlConnection con = null;
#region 得到command
public SqlCommand getcommand(string str)
{
con = new SqlConnection(sql);
con.Open();
SqlCommand com=new SqlCommand(str,con);
return com;
}
#endregion
#region 得到Datareader方法
public SqlDataReader getread(string str)
{
// SqlCommand com = getcommand(str);
// SqlDataReader read = com.ExecuteReader(CommandBehavior.CloseConnection);
return getcommand(str).ExecuteReader(CommandBehavior.CloseConnection);
}
#endregion
#region 得到ExecuteNonQuery方法
public int getnonquety(string str)
{
// SqlCommand com = getcommand(str);
//int result = com.ExecuteNonQuery();
return getcommand(str).ExecuteNonQuery();
}
#endregion
#region 得到ExecuteScalar方法
public int getscalar(string str)
{
// SqlCommand com = getcommand(str);
//int result = (int)com.ExecuteScalar();
return (int)getcommand(str).ExecuteScalar();
}
#endregion