目的为完成一个成绩表查询
成绩表包括sql两个表:花名册,成绩表
其中花名册学号与成绩表学号链接
定义输入学号点击按钮进行查询的控件
查询按钮的代码如下:
private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection myCon = new SqlConnection())
            {
                string str = "select   花名册.*,成绩表.*   from   花名册   right   join   成绩表     on  花名册.学号='" + textBox1.Text + "'";
                ReportDocument oRpt = new ReportDocument();
                SqlDataAdapter sqlAd = new SqlDataAdapter();
                DataSet ds = new DataSet();
                myCon.ConnectionString = "Integrated Security=True;database=MySql;server=(local)";
                myCon.Open();
                SqlCommand select = new SqlCommand(str, myCon);
                sqlAd.SelectCommand = select;
                sqlAd.Fill(dataSet1,str);
                oRpt.Load("C:\\Users\\hp-dv7\\Documents\\Visual Studio 2010\\Projects\\CrystalReportWpfApplication3\\CrystalReportsApplication1\\CrystalReport1.rpt");
                oRpt.SetDataSource(dataSet1);
                crystalReportViewer1.ReportSource = oRpt;             
            }        }
但是输入学号进行查询后没有任何数据显示(貌似dataset没有fill数据)
学生求学!!!

解决方案 »

  1.   

    还真是没有链接成功。+
    “myCon.ServerVersion”引发了“System.InvalidOperationException”类型的异常
    我查文档说是调用sqlcommand前没有建立连接会出现的错误.怎么解决呢?
      

  2.   

            ReceiveCrystalReport rpt = new ReceiveCrystalReport();
                    DataSet ds = new DataSet();
                    string strConn = "Data Source=ITE-03;Initial Catalog=Test;User ID=sa;Password=123456";
                    SqlConnection conn = new SqlConnection(strConn);
                    SqlDataAdapter da = new SqlDataAdapter("Select id,pay_time,type,re from  test", conn);
                    da.Fill(ds, "test");
                    rpt.SetDataSource(ds.Tables["test"]);
                    this.crystalReportViewer1.ReportSource = rpt;http://blog.csdn.net/happy09li/article/details/6931959