2016-05-15 105 views
0

我在CrystalReport ASP.NET中遇到了一些麻煩。在ASP.NET中顯示Crystal Report Viewer

我在ASP.NET中創建一個DataSet,我想用ADO.NET(xml)將它導出到CrystalReport.rpt。但它失敗了。當我建立一個新連接並在報表中放置一個屬性列時,Crystal Report中的Main Report Viewer顯示錯誤的結果。我在Oraclesqldevelop編譯sql查詢,結果很好,沒有任何問題。我想點擊一個按鈕並顯示報告。

這是我的代碼:

protected void btnsumbit_Click(object sender, EventArgs e) 
{ 
    lblerror.Text = ""; 
    if (txtdari.Text == "" || txtdari.Text == null || txtsampai.Text == "" || txtsampai.Text == null) 
    { 
     lblerror.Text = "Tanggal Harus Diisi !!!"; 
    } 
    else 
    { 
     DateTime dt1 = Convert.ToDateTime(txtdari.Text); 
     DateTime dt2 = Convert.ToDateTime(txtsampai.Text); 
     if (dt1.Date > dt2.Date) 
     { 
      lblerror.Text = "Format Tanggal yang Dimasukkan Salah !!!"; 
     } 
     else 
     { 
      OracleConnection conn = new OracleConnection(); 
      conn.ConnectionString = connectionstring; 
      conn.Open(); 
      string sql = "SELECT c.SUB_DISTRIBUTOR , c.MID , c.REKNO , b.ID, b.TERMINAL_ID , b.TANGGAL , b.KETERANGAN , b.DEBIT , b.KREDIT , b.SALDO , b.REFF_NO,b.PRODUK,b.NO_PELANGGAN, b.SN_ID , b.STATUS from MERCHANT c JOIN DAILY b ON (b.REKENING_NO = c.REKNO) where TANGGAL between TO_DATE('"+txtdari.Text+"','mm-dd-yyyy') AND TO_DATE('"+txtsampai.Text+"','mm-dd-yyyy')"; 
      OracleCommand cmd = new OracleCommand(sql, conn); 
      OracleDataAdapter da = new OracleDataAdapter(cmd); 
      DataTable dt = new DataTable(); 
      da.Fill(dt); 
      da.Dispose(); 

      DataSet ds = new DataSet(); 
      ds.Tables.Add(dt); 
      ds.WriteXmlSchema("C:\\Users\\Henz\\Documents\\Visual Studio 2012\\Projects\\LPI\\LPI\\Files\\Sample.xml"); 
      conn.Close(); 

      Response.Redirect("plot.aspx"); 
     } 
    } 
} 

回答

1

由於你的描述,我可以理解,沒有任何錯誤發生。主要問題是你的結果不像你的期望。所以我認爲你應該再次檢查你的命令的參數。請用下面的代碼嘗試:

DateTime dt1 = Convert.ToDateTime(txtdari.Text); 
DateTime dt2 = Convert.ToDateTime(txtsampai.Text); 

////////ARI DATE///////// 
OracleParameter fromDateParameter = new OracleParameter(); 
fromDateParameter.OracleDbType = OracleDbType.Date; 
fromDateParameter.Value = dt1; 

////////SAMPAI DATE///////// 
OracleParameter toDateParameter = new OracleParameter(); 
toDateParameter.OracleDbType = OracleDbType.Date; 
toDateParameter.Value = dt2; 


this.oracleDataAdapter4.SelectCommand = new OracleCommand("SELECT c.SUB_DISTRIBUTOR , c.MID , c.REKNO , b.ID, b.TERMINAL_ID , b.TANGGAL, b.KETERANGAN , b.DEBIT , b.KREDIT , b.SALDO , b.REFF_NO,b.PRODUK,b.NO_PELANGGAN, b.SN_ID , b.STATUS from MERCHANT c JOIN DAILY b ON (b.REKENING_NO = c.REKNO) where TANGGAL BETWEEN :fromDateParameter AND :fromDateParameter)」, conn); 
OracleDataAdapter da = new OracleDataAdapter(cmd); 


da.SelectCommand.Parameters.Add(fromDateParameter);   
da.SelectCommand.Parameters.Add(toDateParameter); 
DataTable dt = new DataTable(); 
da.Fill(dt);