it's confusing, see:

  1. I added a dataset in app_code folder and then added a dummy datatable (field names similar to one in database), so it is visible to Crystal report in ADO.net datasets list.

  2. Dragged all field names from Datatable to Crystal report.

  3. Now as i added code to do in .aspx.cs and it's working perfectly.

    protected void Page_Load(object sender, EventArgs e)
    {

            fillin_cr();
    
    }
    
    string conStr = WebConfigurationManager.ConnectionStrings["LoginDatabaseConnectionString"].ConnectionString;
    
    public void fillin_cr() 
    {
        //DataSet2 ds = new DataSet2();
          DataTable dt = new DataTable();
          using(SqlConnection sqlCon = new SqlConnection(conStr)) 
          using(SqlCommand sqlCom = new SqlCommand("select * from login", sqlCon ))
          using (SqlDataAdapter sda = new SqlDataAdapter(sqlCom))
          {
             try
             {
                 sda.Fill(dt);
                 Response.Write("Filled");
                 //ds.Tables[0].Merge(dt);
    
                 ReportDocument rd = new ReportDocument();
                 rd.Load(Server.MapPath("CrystalReport2.rpt"));
                 rd.SetDataSource(dt);
                 crViewer2.ReportSource = rd;
    
                 Response.Write("ENDED"+ "<br/>");
               }
              catch (Exception exc) 
              {
                 Response.Write("ERROR:"+ exc.Message);
              }
          }
    

But problem is that why it is working ? even i commented this line

ds.Tables[0].Merge(dt);

but still it's working, why ? names which i dragged are from another (dummy) table and the one i mentioned in code is another (though same field names) but i didn't merge and still it's working, why ?

Member Avatar for LastMitch

but still it's working, why ? names which i dragged are from another (dummy) table and the one i mentioned in code is another (though same field names) but i didn't merge and still it's working, why ?

@HunainHafeez

I assuming you are still connected to the database even though you remove that code. That info is still in your table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.