Posted 22 December 2017, 3:01 am EST
Hello,
To first get the data from an SQL Server to DataSet and then use this DataSet to bind a report, you can use the below mentioned code snippet:
Dim adapter As SqlDataAdapter
Dim _dataSet As New DataSet
Dim con As SqlConnection
Dim dt As New DataTable
Dim str As String = "Data Source = DatasourceName; Initial Catalog = DBName; User ID = ID; Password = pwd"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
C1FlexReport1.Load("../../Cars_SQLServer.flxr", "Products")
_dataSet.Tables.Add(dt)
Using con = New SqlConnection()
con.ConnectionString = str
con.Open()
Using adapter = New SqlDataAdapter("Select * from products", con)
adapter.Fill(dt)
End Using
End Using
C1FlexReport1.DataSource.Recordset = dt
C1FlexViewer1.DocumentSource = C1FlexReport1
End Sub
In order to bind the report to the database, use the below mentioned code snippet:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
C1FlexReport1.Load("../../Cars_SQLServer.flxr", "Products")
C1FlexReport1.DataSource.ConnectionString = "Provider = [b]SQLOLEDB[/b];Persist Security Info=True;User ID=ID;Password=pwd;Initial Catalog=DBName;Data Source=DataSourceName"
C1FlexReport1.DataSource.RecordSource = "Products" 'Table's name
C1FlexViewer1.DocumentSource = C1FlexReport1
End Sub
The data provider in this case is SQLOLEDB.
Let us know if you need further assistance.
Best Regards,
Esha