adding a "Data From Sql Connection"

Stimulsoft Reports.NET discussion
Post Reply
ely
Posts: 4
Joined: Wed Jan 20, 2010 4:28 am

adding a "Data From Sql Connection"

Post 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....
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

adding a "Data From Sql Connection"

Post by Edward »

Hi

What was the product version number you used?

Thank you.
ely
Posts: 4
Joined: Wed Jan 20, 2010 4:28 am

adding a "Data From Sql Connection"

Post by ely »

Hi & Thank you
2008.1.129
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

adding a "Data From Sql Connection"

Post 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.
Post Reply