我在CrystalReport ASP.NET中遇到了一些麻烦。
我在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");
}
}
}
答案 0 :(得分: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);