Riki Dev Riki Dev - 2 months ago 25
SQL Question

How add dataset into report c#

Hello I have problem on create report with crystal report c#,
I should insert the result of this SqlAdapter in a c # report , but do not know how to do

String Query = "SELECT Utente.LogoAzienda,Preventivo.DataInserimento,Preventivo.RiferimentoInterno,Preventivo.Testata,Preventivo.Chiusura,Cliente.Titolo,Cliente.RagioneSociale,Cliente.Indirizzo,Cliente.Cap,Cliente.Citta,Cliente.Provincia FROM Preventivo inner join Cliente on Cliente.IdCliente = Preventivo.IdCliente inner join Utente on Preventivo.UtenteCreazione = Utente.Username";

SqlConnection conn = db.apriconnessione();

DataStampaPreventivoCompleto d = new DataStampaPreventivoCompleto();
SqlDataAdapter da = new SqlDataAdapter(Query, conn);
da.Fill(d, d.Tables[0].TableName);

Answer

Here is an example to bind dataset to crystal report:

private void CrystalFormView_Load(object sender, EventArgs e)
{
  string connection = ConfigurationManager.ConnectionStrings["sqlbill"].ConnectionString;
  string provider = ConfigurationManager.ConnectionStrings["sqlbill"].ProviderName;
  SqlConnection con = new SqlConnection(connection);
  SqlDataAdapter sda = new SqlDataAdapter("select product as Product,productid as ProductId,quantity as Quantity from productdata", con);

  DataSet ds = new DataSet();
  sda.Fill(ds);
  ds.Tables[0].TableName = "BILLTEST";

  BillCrystalReport bill = new BillCrystalReport();  
  bill.SetDataSource(ds);

  bill.VerifyDatabase();

  crystalReportViewer1.ReportSource = bill;
  crystalReportViewer1.RefreshReport();
}

For more, please check this link: http://www.codeproject.com/Tips/754037/Bind-Crystal-Reports-with-Dataset-or-Datatable

Comments