大家多多共享啊
我想调用下面类中 Getdataset中的ds在窗体上用,但调不出来,谁帮我看看要怎么写啊
class DataAccess
{
public static string Connectionstring = "Data Source=.;Initial Catalog=CJGL;Integrated Security=true";
public bool ExecuteSql(string sql)
{
SqlConnection con = new SqlConnection(DataAccess.Connectionstring);
SqlCommand cmd = new SqlCommand(sql, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
}
public SqlDataReader Getreader(string sql)
{
SqlConnection con = new SqlConnection(DataAccess.Connectionstring);
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = null;
try
{
con.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(Exception ex)
{
dr.Close();//每次调用完DataReader对象后都要关闭的
con.Dispose();
cmd.Dispose();
throw new Exception(ex.ToString());
}
return dr;
}
public DataSet Getdataset(string sql, string tablename)
{
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(DataAccess.Connectionstring);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
try
{
da.Fill(ds, tablename);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
finally
{
con.Close();
con.Dispose();
da.Dispose();
}
return ds;
}
public int Getcount(string sql)
{
SqlConnection con = new SqlConnection(DataAccess.Connectionstring);
SqlCommand cmd = new SqlCommand(sql, con);
try
{
con.Open();
int count = (int)cmd.ExecuteScalar();
return count;
}
catch
{
return 0;
}
finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
}
public bool Checkadmin(string strname, string strpwd)
{
string sql;
//strname =NameReplace(strname);
sql = "select count(1) from UserInfo where Userid='"+strname+"'and Userpwd='" + strpwd + "'";
if (Getcount(sql) > 0)
{
return true;
}
else
{
return false;
}
}
}