Page 1 of 1
Add Table By code
Posted: Thu Apr 25, 2013 4:42 pm
by raed
I downloaded trial version 2013.1 to try your product.
I tried to create report using c# code the problem that I cannot add Stitable object because it raise the following exception:
Index was out of range. Must be non-negative and less than the size of the collection
I use the following code
StiReport report = new StiReport();
StiPage page = report.Pages[0];
StiTable Table1 = new StiTable();
page.Components.Add(Table1);
report.Compile();
report.Show();
Notes:
When I tried to add databand or any other object it is working fine
I tired to add the datasource and cells but the same
If I save the report using previous code then I open it using the designer its working fine even If I open it using VS.
thanx
Re: Add Table By code
Posted: Fri Apr 26, 2013 10:52 am
by Alex K.
Hello,
Please try to add the necessary component in designer then open Code tab and see how to create this components. Then you can use the similar code in your project.
Thank you.
Re: Add Table By code
Posted: Tue Apr 30, 2013 7:43 am
by raed
Thank u very much it is working
Re: Add Table By code
Posted: Tue Apr 30, 2013 8:02 am
by Alex K.
Hello,
We are always glad to help you!
Thank you.
Re: Add Table By code
Posted: Tue Apr 30, 2013 10:45 am
by raed
I tried to add the datasource to the report from code
I read one of ur replies on the forum how to do that :
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Code: Select allforeach (DataColumn col in dataTableDS1.Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
But the problem that the datasource created without columns bcz I don't know what u mean by dataTableDS1.Columns
in ur last code how to add the columns to the data source (how to define the data table dataTableDS1)
thanx
Re: Add Table By code
Posted: Tue Apr 30, 2013 12:23 pm
by Alex K.
Hello,
Please check the following code:
Code: Select all
StiReport report = new StiReport();
string newConnectionString = @"Data Source=ALEKSEYPC\SE2012;Initial Catalog=Northwind;Integrated Security=True";
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
StiSqlSource Categories = new StiSqlSource("Connection", "Categories", "Categories", "SELECT * FROM Categories", true, false);
report.Dictionary.DataSources.Add(Categories);
using (SqlConnection connection = new SqlConnection(newConnectionString))
{
SqlDataAdapter dataCategories = new SqlDataAdapter("select * from Categories", connection);
DataTable dataTableCategories = new DataTable();
dataCategories.Fill(dataTableCategories);
foreach (DataColumn col in dataTableCategories.Columns)
{
Categories.Columns.Add(col.ColumnName, col.DataType);
}
}
Thank you.
Re: Add Table By code
Posted: Tue Apr 30, 2013 3:31 pm
by raed
Thank u very much
Re: Add Table By code
Posted: Wed May 01, 2013 6:55 am
by Andrew
Hello,
We are glad to help you!