Page 1 of 1

adding a "Data From Sql Connection"

Posted: Mon Jan 25, 2010 4:43 am
by ely
Hi
I want my datasource type be "Data From Sql Connection" and I want to add it by code.
I write this code:

public class MyDataSource:Stimulsoft.Report.Dictionary.StiSqlSource
{
public MyDataSource(String conname,String name,String command):
base(conname,name,name,command,True,False,30)
{
}
}
-------------------------------------------
In My Evant:

StimulSoft.Report.StiReport report=new StimulSoft.Report.StiReport();
MyDataSource data = new MyDataSource("MyDBName","MyTableName","select field1,field2 from MyTableName");
data.Columns.AddRange(new StimulSoft.Report.Dictionary.StiDataColumn[] {
new StimulSoft.Report.Dictionary.StiDataColumn("field1","field1","field1",typeof(string)),
new StimulSoft.Report.Dictionary.StiDataColumn("field2","field2","field2",typeof(string))});
report.DataSources.Add(data);
report.RegData("MyDBName",MySqlConnection);
report.Design();


but when I want to edit my Datasource in design mode this error comes:Data Adaptor Not Found.
if it is possible to add a datasource in this way where my mistake is....

adding a "Data From Sql Connection"

Posted: Mon Jan 25, 2010 8:18 am
by Edward
Hi

What was the product version number you used?

Thank you.

adding a "Data From Sql Connection"

Posted: Mon Jan 25, 2010 10:48 pm
by ely
Hi & Thank you
2008.1.129

adding a "Data From Sql Connection"

Posted: Thu Jan 28, 2010 2:54 am
by Ivan
Hello,
ely wrote:I want my datasource type be "Data From Sql Connection" and I want to add it by code.
but when I want to edit my Datasource in design mode this error comes:Data Adaptor Not Found.
if it is possible to add a datasource in this way where my mistake is....
Please use following code:

Code: Select all

        public class MyDataSource : Stimulsoft.Report.Dictionary.StiSqlSource
        {
            public MyDataSource() : this("", "", "")
            {
            }

            public MyDataSource(String conname, String name, String command) :
            base(conname, name, name, command, true, false, 30)
            {
            }
        }

        public class MyDataSourceAdapter : Stimulsoft.Report.Dictionary.StiSqlAdapterService
        {
            public override string ServiceName
            {
                get
                {
                    return "Data from MyData Connection";
                }
            }

            public override Type GetDataSourceType()
            {
                return typeof(MyDataSource);
            }

            public MyDataSourceAdapter() : base()
            {
            }
        }
In init part of your application:

Code: Select all

            StiConfig.Services.Add(new MyDataSourceAdapter());
In your event:

Code: Select all

            Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport();
            MyDataSource data = new MyDataSource("MyDBName", "MyTableName", "select field1,field2 from MyTableName");
            data.Columns.AddRange(new Stimulsoft.Report.Dictionary.StiDataColumn[] {
                new Stimulsoft.Report.Dictionary.StiDataColumn("field1","field1","field1",typeof(string)),
                new Stimulsoft.Report.Dictionary.StiDataColumn("field2","field2","field2",typeof(string))});
            report.DataSources.Add(data);
            report.RegData("MyDBName", MySqlConnection);
            report.Design();
Thank you.