无法将类型System.Data.SqlClient.SqlDataReader”隐式转换为System.Data.OleDb.OleDbDataReade
请问这段代码哪错了?应该怎么改呢?publicclassDBHelper{publicstaticDataSetGetDataSet(stringSql){SqlConn...
请问这段代码哪错了?应该怎么改呢?
public class DBHelper
{
public static DataSet GetDataSet(string Sql)
{
SqlConnection conn=new SqlConnection(GetConnStr());
SqlDataAdapter da=new SqlDataAdapter(Sql,conn);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;
}
public static SqlDataAdapter GetReader(string sql)
{
SqlDataReader dr=null;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
conn.Close();
}
return dr;
}
public static int ExecScalar(String sql)
{
int ret;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
ret=(int)cmd.ExecuteScalar();
}
finally
{
conn.Close();
}
return ret;
}
public static int ExecSql(string sql)
{
int ret;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
ret=cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
return ret;
}
public static string GetConnStr()
{
return System.Configuration.ConfigurationSettings.AppSettings["Db"];
}
}
应该是System.Data.SqlClient.SqlDataReader”隐式转换为“System.Data.SqlClient.SqlDataAdapter” 展开
public class DBHelper
{
public static DataSet GetDataSet(string Sql)
{
SqlConnection conn=new SqlConnection(GetConnStr());
SqlDataAdapter da=new SqlDataAdapter(Sql,conn);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;
}
public static SqlDataAdapter GetReader(string sql)
{
SqlDataReader dr=null;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
conn.Close();
}
return dr;
}
public static int ExecScalar(String sql)
{
int ret;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
ret=(int)cmd.ExecuteScalar();
}
finally
{
conn.Close();
}
return ret;
}
public static int ExecSql(string sql)
{
int ret;
SqlConnection conn=new SqlConnection(GetConnStr());
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
try
{
ret=cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
return ret;
}
public static string GetConnStr()
{
return System.Configuration.ConfigurationSettings.AppSettings["Db"];
}
}
应该是System.Data.SqlClient.SqlDataReader”隐式转换为“System.Data.SqlClient.SqlDataAdapter” 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询