How to make a CrystalReport using data from several tables?

Nel

New member
Joined
Nov 10, 2011
Messages
3
Programming Experience
Beginner
Hi,

I have a database with three tables, and I want to make a crystal report using some of the data from each of them.
Here is my code, but I am new in this and I don't know how to help myself:

ReportDocument cryRpt = new ReportDocument();
string comstring = "SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA, Min(NALOG1.POCKM) AS MinOfPOCKM, Max(NALOG1.KRAJKM) AS MaxOfKRAJKM, (Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR where (((NOVI.GBR)>='?' And (NOVI.GBR)<='?') AND ((NOVI.AB)='?') or ((NOVI.ab)='?')) AND ((NALOG1.DATA)>=?) and ((NALOG1.DATA)<=?)) GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA";
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText = comstring;
if (radioButton4.Checked==true){
command.Parameters.AddWithValue("@gbr1", textBox1.Text);
command.Parameters.AddWithValue("@gbr2", textBox1.Text);
}
if (radioButton5.Checked==true){

command.Parameters.AddWithValue("@gbr1", "1001");
command.Parameters.AddWithValue("@gbr2", "1020");
}
if (radioButton6.Checked==true){

command.Parameters.AddWithValue("@gbr1","1020" );
command.Parameters.AddWithValue("@gbr2", "1088");
}
if (radioButton7.Checked == true)
{
command.Parameters.AddWithValue("@gbr1", "1001");
command.Parameters.AddWithValue("@gbr2", "1088");
}
if(checkBox1.Checked==true){
command.Parameters.AddWithValue("@ab1", 1);
command.Parameters.AddWithValue("@ab2", 1);
}
else if (checkBox2.Checked==true)
{
command.Parameters.AddWithValue("@ab1", 2);
command.Parameters.AddWithValue("@ab2", 2);
}
else if((checkBox1.Checked==true) && (checkBox2.Checked==true))
{
command.Parameters.AddWithValue("@ab", 1);
command.Parameters.AddWithValue("@ab",2);
}
command.Parameters.AddWithValue("@data1", dateTimePicker1.Value);
command.Parameters.AddWithValue("@data2", dateTimePicker2.Value);
DataSet dataSet2=new DataSet();
conn.Open();

OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(comstring, conn));
OleDbCommand command1 = new OleDbCommand();
command1.Connection = conn;
oleDBDataAdapter1.SelectCommand.CommandText=comstring;
dataSet2.Clear();
oleDBDataAdapter1.Fill(dataSet2);

cryRpt.SetDataSource(dataSet2);
crystalReportViewer1.DisplayToolbar=true;
crystalReportViewer1.ReportSource = cryRpt;

cryRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
crystalReportViewer1.Refresh();
conn.Close();

I know I have some redundant code, but it's not very clear to me how to do this.
Please help me if anybody have an idea.
Thanks
 
Back
Top Bottom