0

I have a problem in my Windows Forms application. My report does not show anything, I don't know what the problem is. I want to create a report with a specific query from SQL Server 2008 and add conditions, but I just write the query without condition and is showing nothing, my database is not empty.

I have this code:

SqlConnection Conne = new SqlConnection("Data Source=GONZALO\\SQLEXPRESS;Initial Catalog=DATABASE;Integrated Security=true");
Conne.Open();   

ReportedeMant Informe2 = new ReportedeMant();
RMant rll2 = new RMant();

string query = "SELECT * FROM Mantenimientos M " +
                "INNER JOIN Canales C ON M.IDCanal=C.IDCanal " +
                "INNER JOIN Region R ON M.IDRegion=R.IDRegion " +
                "INNER JOIN Equipos E ON M.Serie = E.Serie " +
                "INNER JOIN Fallas F ON M.IDTipoFalla = F.IDTipoFalla " +
                "INNER JOIN Problema_Mantenimiento PM ON M.IDProblema = PM.IDProblema " +
                "INNER JOIN Resultado_Mant RM ON M.IDResultado = RM.IDResultado " +
                "INNER JOIN Servicio S ON M.IDServicio = S.IDServicio " +
                "INNER JOIN TipoMantenimiento TM ON M.IDTipoMant = TM.IDTipoMant " +
                "INNER JOIN Clientes Cli ON M.CodigoCliente = Cli.CodigoCliente";
               //    DatabaseDataSet dsLS = new DatabaseDataSet ();

DataSet dsLS = new DataSet();

SqlCommand com = new SqlCommand(query,Conne);

try
{
    SqlDataAdapter q = new SqlDataAdapter(com);
    q.Fill(dsLS);

    Informe2.SetDataSource(dsLS);
    rll2.crystalReportViewer1.ReportSource = Informe2;
}
catch (Exception eex)
{
    MessageBox.Show(eex.Message);
}

rll2.Show();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
gon009
  • 1
  • 2

1 Answers1

0

If any one of the INNER JOINs returns no records then the query as a whole will return no records. But I cannot tell what would be the right thing to do without knowing the data relations and the intent of the query.

As a guess I'd say LEFT JOIN for at least that first join.

Whatever you do build the query one JOIN at a time, run it in your sql environment and see the results as you go along.

Helpful Link 1

Helpful Link 2

Community
  • 1
  • 1
radarbob
  • 4,964
  • 2
  • 23
  • 36