Add Table By code
Add Table By code
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
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
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.
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
Thank u very much it is working
Re: Add Table By code
Hello,
We are always glad to help you!
Thank you.
We are always glad to help you!
Thank you.
Re: Add Table By code
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
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
Hello,
Please check the following code:
Thank you.
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);
}
}
Re: Add Table By code
Thank u very much
Re: Add Table By code
Hello,
We are glad to help you!
We are glad to help you!