我有这个代码,我从昨天起就一直在努力,但是没有按预期工作。
现在的问题是,我有2个数据集来从数据库生成信息到Reportview,然后在一个数据集上,我使用2个表(Transaction和Account_info)来生成数据。两者都正确地提供了他们的信息,没有问题,但现在问题来了。
如果我将标识符(账号)搜索到生成账单对A先生说,它会显示A和B先生的详细信息,然后如果我为B先生设置标识符,它将显示B先生的账户对账单和A.先生我只想让它为一个人发表声明。即。如果A先生的账号只显示A先生的数据,而B先生的账号只显示B先生的数据。
数据集是DataSet1,我希望它只显示一个客户的信息
我的代码如下所示:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace TmpZ
{
public partial class BalanceSheet : Form
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
public BalanceSheet()
{
InitializeComponent();
}
private void BalanceSheet_Load(object sender, EventArgs e)
{
}
private void reportViewer1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (accountNo1.Text == "")
{
MessageBox.Show("Please Enter Account Number");
}
else
{
DataTable dtb = new DataTable();
DataTable dtb2 = new DataTable();
dtb2 = GetAddressInfo(dtb2);
dtb = GenerateBankStatement(dtb);
reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rpd = new ReportDataSource("DataSet1", dtb);
ReportDataSource rpd2 = new ReportDataSource("DataSet2", dtb2);
reportViewer1.LocalReport.DataSources.Add(rpd);
reportViewer1.LocalReport.DataSources.Add(rpd2);
reportViewer1.RefreshReport();
}
}
private DataTable GetAddressInfo(DataTable dt)
{
using (SqlConnection cn = new SqlConnection(constring))
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select fullname as [fullname], accountNo as [accountNo], ccy as [ccy] from account_info where accountNo = '" + accountNo1.Text + "'", cn);
da.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return dt;
}
private DataTable GenerateBankStatement(DataTable dt)
{
using (SqlConnection cn = new SqlConnection(constring))
{
try
{
string dateF = Convert.ToDateTime(dateFrom.Text).ToString("dd-MM-yyyy");
string dateT = Convert.ToDateTime(dateTo.Text).ToString("dd-MM-yyyy");
SqlDataAdapter da = new SqlDataAdapter("SELECT account_info.fullname as [fullname], account_info.accountNo as [accountNo], account_info.ccy as [ccy], account_info.address as [address] , transactions.id as [id], transactions.transaction_desc as [transaction_desc], transactions.credit as [credit], transactions.debit as [debit], transactions.balance as [balance], transactions.transaction_date as [transaction_date] FROM transactions CROSS JOIN account_info WHERE(account_info.accountNo = '" + accountNo1.Text + "') AND(transactions.transaction_date BETWEEN '" + dateF + "' AND '" + dateT + "')", cn);
da.Fill(dt);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return dt;
}
}
}
答案 0 :(得分:0)
好的我修好了。我不得不修复一些非常错误的查询,它现在正如我所料。如果某人将来需要这样的东西。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace Tmpz
{
public partial class BalanceSheet : Form
{
string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
public BalanceSheet()
{
InitializeComponent();
}
private void BalanceSheet_Load(object sender, EventArgs e)
{
}
private void reportViewer1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (accountNo1.Text == "")
{
MessageBox.Show("Please Enter Account Number");
}
else
{
DataTable dtb = new DataTable();
DataTable dtb2 = new DataTable();
dtb2 = GetAddressInfo(dtb2);
dtb = GenerateBankStatement(dtb);
reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rpd = new ReportDataSource("DataSet1", dtb);
ReportDataSource rpd2 = new ReportDataSource("DataSet2", dtb2);
reportViewer1.LocalReport.DataSources.Add(rpd);
reportViewer1.LocalReport.DataSources.Add(rpd2);
reportViewer1.RefreshReport();
}
}
private DataTable GetAddressInfo(DataTable dt)
{
using (SqlConnection cn = new SqlConnection(constring))
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select fullname as [fullname], accountNo as [accountNo], ccy as [ccy] from account_info where accountNo = '" + accountNo1.Text + "'", cn);
da.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return dt;
}
private DataTable GenerateBankStatement(DataTable dt)
{
using (SqlConnection cn = new SqlConnection(constring))
{
try
{
string dateF = Convert.ToDateTime(dateFrom.Text).ToString("dd-MM-yyyy");
string dateT = Convert.ToDateTime(dateTo.Text).ToString("dd-MM-yyyy");
// SqlDataAdapter da = new SqlDataAdapter("SELECT account_info.fullname as [fullname], account_info.accountNo as [accountNo], account_info.ccy as [ccy], account_info.address as [address] , transactions.id as [id], transactions.transaction_desc as [transaction_desc], transactions.credit as [credit], transactions.debit as [debit], transactions.balance as [balance], transactions.transaction_date as [transaction_date] FROM transactions CROSS JOIN account_info WHERE(transactions.accountNo1 = '" + accountNo1.Text + "') AND(transactions.transaction_date BETWEEN '" + dateF + "' AND '" + dateT + "')", cn);
SqlDataAdapter da = new SqlDataAdapter("select id as [id], transaction_desc as [transaction_desc], credit as [credit], debit as [debit], balance as [balance], transaction_date as [transaction_date] from transactions where accountNo1 = '" + accountNo1.Text + "' and transaction_date between '"+ dateF + "' and '"+ dateT + "'", cn);
da.Fill(dt);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return dt;
}
}
}