I use Crystal report in my c# application, this is the code i use:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
switch (dataGridView1.Columns[e.ColumnIndex].Name)
{
case "FicheArticle":
if (con.State != ConnectionState.Open)
{
con.Open();
}
SqlCommand ficheCmd = new SqlCommand("SELECT CodeArticle, LibArticleFr, InfomationsDetaille, StockActuel FROM Article WHERE CodeArticle = @code", con);
ficheCmd.Parameters.AddWithValue("@code",Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value));
DataSet ficheDs = new DataSet();
SqlDataAdapter dscmd = new SqlDataAdapter(ficheCmd);
dscmd.Fill(ficheDs, "Article");
CrystalReport7 objRpt7 = new CrystalReport7();
objRpt7.SetDataSource(ficheDs);
crystalReportViewer7.ReportSource = objRpt7;
crystalReportViewer7.Refresh();
con.Close();
break;
}
}
The query is correct because i tested it before but the Crystal report don't show anything. So where is the error??
I found the error, the datasource of the report is linked to other table than
Article table, and it is not set in the code. So the tables of the datasource
must be the same in the code.