Windows Forms Cyrstal Report: Best practice

Jerry Lipan 916 Reputation points
2022-01-26T05:06:49.433+00:00

Hi,

I've successful shown a Windows Forms SAP Crystal Report. I'm using

  1. Data Adapter
  2. Data Set

to store the value, then display

168564-26012022-001.png

This is my code,

   private void frmIncidentMaster_GetIncidents_Show_Load(object sender, EventArgs e)  
        {  
  
            BindReport();  
  
        }  
  
  
        private void BindReport()  
        {  
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString);  
            try  
            {  
                SqlCommand cmd = new SqlCommand("select * from [dbo].[rptIncidentMaster_GetIncidents] " +  
                                    "Where Batch_Id = '" + paramData.Batch_Id + "'", con);  
                cmd.CommandType = CommandType.Text;  
  
                SqlDataAdapter da = new SqlDataAdapter(cmd);  
  
                DataSet ds = new DataSet();  
  
                da.Fill(ds, "rptIncidentMaster_GetIncidents");  
  
                IncidentMaster_GetIncidents rpt = new IncidentMaster_GetIncidents();  
                rpt.SetDataSource(ds);  
  
                crystalReportViewer1.ReportSource = rpt;  
                crystalReportViewer1.RefreshReport();  
  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message, "Error");  
            }  
  
        }  
  
         
  
  

Is this the best practice? No need to close connection & dispose connection? No need to dispose Crystal Report Object ?

Last time I'm using Data Adapter and Data Set in Active Server Pages ( ASP Classic ) Programming. Then, no more

If Windows Forms having new technology to retrieve value then send it into Crystal Report View, please tell me. May be I'm a overlook

Please help

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
750 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful