Add Datasource Manuel

Hello;

My question is simple.How to add datasource to project manuel? I dont want to configure from report.Example When I send a SQL query from my program to report,Report must undestand to datasource manuel.

I completed my reports with design with report designer.But I want to design with codes in C#.

Comments

  • edited 6:24AM
    Hello,

    If your datasource comes from an application, it is better to register it in a report using the report.RegisterData(...) call.
  • edited 6:24AM
    AlexTZ wrote: »
    Hello,

    If your datasource comes from an application, it is better to register it in a report using the report.RegisterData(...) call.

    Yes,I'm using report.RegisterData(...); But For this I must desing in project which dataset Register.My question is,I dont want to register any data in report.When I send a datasource to report,report designer recognize it automatically.And I only design which data can available.
  • edited 6:24AM
    If you want to create a datasource in code:
      Report report = new Report();
      // load an existing report from a file
      report.Load("myreport.frx");
    
      // create the connection object
      MsAccessDataConnection conn = new MsAccessDataConnection();
      conn.Name = "Connection1";
      conn.DataSource = @"d:\crosstest.mdb";
      report.Dictionary.Connections.Add(conn);
    
      // create all connection tables and views
      conn.CreateAllTables();
      // enable the "cross" table
      report.GetDataSource("cross").Enabled = true;
    

    Is this what you need?
  • edited 6:24AM
    AlexTZ wrote: »
    If you want to create a datasource in code:
      Report report = new Report();
      // load an existing report from a file
      report.Load("myreport.frx");
    
      // create the connection object
      MsAccessDataConnection conn = new MsAccessDataConnection();
      conn.Name = "Connection1";
      conn.DataSource = @"d:\crosstest.mdb";
      report.Dictionary.Connections.Add(conn);
    
      // create all connection tables and views
      conn.CreateAllTables();
      // enable the "cross" table
      report.GetDataSource("cross").Enabled = true;
    

    Is this what you need?

    Yep,but a problem about Datasets,

    My Query Code is ;
    SqlConnection con = new SqlConnection(ConnectionString());
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter("MyQuery()", con);
    da.SelectCommand.ExecuteNonQuery();
    da.Fill(ds, "Test");
    con.Close();
    

    Than For Report I'm using Your code example like that
    report1.Load(...);
    MsSqlDataConnection Reportconn = new MsSqlDataConnection();
    Reportconn.ConnectionString = ConnectionString;
    report1.Dictionary.Connections.Add(Reportconn);
    Reportconn.CreateAllTables();
    Reportconn.DataSet.Tables.Add("TableName");
    report1.RegisterData(ds.Tables[0], "Test");
    report1.Show();
    

    But Now,I can see Only one row in the report,problem is about databind,how can report recognize Databind name from code,and I can see all of rows.


  • edited 6:24AM
    To create a report, use the following code:
    // fill the data table
    SqlConnection con = new SqlConnection(ConnectionString());
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter("MyQuery()", con);
    da.SelectCommand.ExecuteNonQuery();
    da.Fill(ds, "Test");
    con.Close();
    
    // register it in a report and run the report designer
    report1.RegisterData(ds.Tables[0], "Test");
    report1.Design();
    

    When you finish with the design, save report to a file. To run the report:
    // fill the data table
    SqlConnection con = new SqlConnection(ConnectionString());
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter("MyQuery()", con);
    da.SelectCommand.ExecuteNonQuery();
    da.Fill(ds, "Test");
    con.Close();
    
    // register the data in the same way as when you design a report
    report1.Load(...);
    report1.RegisterData(ds.Tables[0], "Test");
    report1.Show();
    
  • edited 6:24AM
    Alex Thanks Man,and finally I want to ask last question,then I will shut up long long time:),For our project,I designed a report , than I will send it to database,if someone want new report or redesign about report,I send query to database and report is loaded from database by the stream,but when I change to report,how can update report and send it to database without reload the database like only save button,is there any probability for this ?
  • edited 6:24AM
    Storing and loading a report to/from a DB is completely up to you [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> You may find the following demo useful (Demos\C#\CustomOpenSaveDialogs) if you store reports in DB.[/img]
  • edited 6:24AM
    How will a designer file? How will be the datasource? Will there be any datasource table in report? How will be the text for example- [products.productname]
  • edited 6:24AM
    Andrei wrote: »

    Yep,but a problem about Datasets,

    My Query Code is ;
    SqlConnection con = new SqlConnection(ConnectionString());
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter("MyQuery()", con);
    da.SelectCommand.ExecuteNonQuery();
    da.Fill(ds, "Test");
    con.Close();
    

    Than For Report I'm using Your code example like that
    report1.Load(...);
    MsSqlDataConnection Reportconn = new MsSqlDataConnection();
    Reportconn.ConnectionString = ConnectionString;
    report1.Dictionary.Connections.Add(Reportconn);
    Reportconn.CreateAllTables();
    Reportconn.DataSet.Tables.Add("TableName");
    report1.RegisterData(ds.Tables[0], "Test");
    report1.Show();
    

    But Now,I can see Only one row in the report,problem is about databind,how can report recognize Databind name from code,and I can see all of rows.

    My Question is. How will be the datasource in designer file frx. It is giving me error on [Test.Name]. Test not foud. Please help. No proper documentation for fast reports.

Leave a Comment