Auto-Create columns from datasource

Stimulsoft Reports.WEB discussion
Post Reply
hunter
Posts: 20
Joined: Thu Sep 08, 2011 7:13 pm
Location: Sydney, AUS

Auto-Create columns from datasource

Post by hunter »

I am evaluating this product for use in multiple applications we have. I am finding the lack of examples to do SQL database connections and data sources in the back end of the designer somewhat lacking. I have pieced the basics together from various forum posts.

What i would like to do is, when adding each datasource for a new report, it should auto retrieve the column names. I notice it can be done via the front end, but i cannot see any method from the back end. I don't want my users typing in SQL to create there own datasources - they should all be listed ready for them.

I saw this post: http://forum.stimulsoft.com/Default.aspx?g=posts&t=4715
which talks about this. I downloaded the 1 Sept trial version, and still can't see how to do it. Can someone point me in the right direction? (I know i can write some code to do this, but i would think that functionality is already in there somewhere).

Thanks - the rest of the product looks really good!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Auto-Create columns from datasource

Post by Alex K. »

Hello,

You can use the following code.
New connection string:

Code: Select all

report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Add DataSources:

Code: Select all

StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Add Columns:

Code: Select all

foreach (DataColumn col in dataTableDS1.Columns)
{
     DS1.Columns.Add(col.ColumnName, col.DataType);
}
Thank you.
Arjune
Posts: 20
Joined: Mon Jan 28, 2019 9:26 am

Re: Auto-Create columns from datasource

Post by Arjune »

Hello,

I have the same issue, and I do not understand where the variable "dataTableDS1" comes from, in the code you have posted.
(I am implementing this in Javascript, by the way). Could you be more specific about how I could get the dataTableDS1 object correctly filled with the columns of the table?
foreach (DataColumn col in dataTableDS1.Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
Lech Kulikowski
Posts: 6263
Joined: Tue Mar 20, 2018 5:34 am

Re: Auto-Create columns from datasource

Post by Lech Kulikowski »

Hello,

You can use the following code:

Code: Select all

var connection = new SqlConnection("connection");
var adapterDataTable1 = new SqlDataAdapter("select * from Table1", connection);
var dataTable1 = new DataTable();
adapterDataTable1.Fill(dataTable1);

foreach (DataColumn col in dataTable1.Columns)
{
    DS1.Columns.Add(col.ColumnName, col.DataType);
}
Thank you.
Arjune
Posts: 20
Joined: Mon Jan 28, 2019 9:26 am

Re: Auto-Create columns from datasource

Post by Arjune »

Hi Lech,

Thank you for your answer. Though, since I am working using JS (Stimulsoft.Report.JS), I don't really get how I can convert the dataType I have from my NodeJS SQL Adapter to a Stimulsoft.System.Type object... Unless you can provide me with the solution here, I will create a post in the appropriate section of the forum.

Kind Regards,
Lech Kulikowski
Posts: 6263
Joined: Tue Mar 20, 2018 5:34 am

Re: Auto-Create columns from datasource

Post by Lech Kulikowski »

Hello,

Please check the following link:
https://admin.stimulsoft.com/documentat ... erence-js/

Thank you.
Post Reply