none
无法将类型system.data.dataset隐式转换为mydataset,存在一个显式转换(是否缺少强制转换) RRS feed

  • 问题

  • using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using CrystalDecisions.Shared;
    using CrystalDecisions.CrystalReports.Engine;
    using DB_Operation;//我定义的数据库类
    using System.Data.SqlClient;
    using System.Web.Configuration;


    public partial class DownCode_myreport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            //string conString = WebConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
            //string sql = "select EmployeeId1 as EmployeeId,hisDogName1 as hisDog from forSubReport1";
            //SqlConnection conn = new SqlConnection(conString);
            //SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
            //conn.Open();
            //myDataSet ds1 = new myDataSet();
            //sda.Fill(ds1, "forSubReport");我用以上语句没问题!

            myDataSet ds1 = new myDataSet();//是我定义的数据集
            string cmd = "select EmployeeId1 as EmployeeId,hisDogName1 as hisDog from forSubReport1";
            DBConnection db = new DBConnection();
            ds1 = db.getDataSet(cmd, "forSubReport");//在这里我用我定义的类,就不行,总是提示我“无法将类型system.data.dataset隐式转换为mydataset,存在一个显式转换(是否缺少强制转换)”我曾尝试as myDataSet,但不行;很奇怪,无非就是把上面注释掉的内容给写到类里去,怎么就不行呢,请高手指点!

            ReportDocument myReport = new ReportDocument();
            string reportPath = Server.MapPath("~/App_Code/myreport.rpt");
            myReport.Load(reportPath);
            myReport.SetDataSource(ds1);
            CrystalReportViewer1.ReportSource = myReport;

        }
    }
    类的内容
     public class DBConnection
        {
            private static string conString = WebConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlDataAdapter sda = null;

            public DataSet getDataSet(string sql,string tableName)
            {
                conn = new SqlConnection(conString);
                sda = new SqlDataAdapter(sql, conn);
                conn.Open();
                DataSet ds = new DataSet();
                try
                {
                    sda.Fill(ds,tableName);
                }
                catch
                {
      &n

    2009年5月19日 6:57

答案

全部回复