Page 1 of 1

Auto-Create columns from datasource

Posted: Thu Sep 08, 2011 7:50 pm
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!

Auto-Create columns from datasource

Posted: Fri Sep 09, 2011 8:33 am
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.

Re: Auto-Create columns from datasource

Posted: Mon Jan 28, 2019 9:30 am
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);
}

Re: Auto-Create columns from datasource

Posted: Tue Jan 29, 2019 11:12 pm
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.

Re: Auto-Create columns from datasource

Posted: Wed Jan 30, 2019 9:26 am
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,

Re: Auto-Create columns from datasource

Posted: Thu Jan 31, 2019 7:03 am
by Lech Kulikowski
Hello,

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

Thank you.