Crystal Reports From SQL Query String

March 24, 2018 | Author: lmduong868556 | Category: Microsoft Excel, Sql, Software Development, Data Management, Application Software


Comments



Description

Crystal Reports from SQL Query String In usual practice , Crystal Reports we are getting from pre definedcolumns. But we can make Crystal Reports from Dynamic column . Here we are going to do the dynamic Crystal Reports from SQL statements . That is we enter SQL in textbox and get the Crystal Reports according to the SQL statement. All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure . Create a new VB.NET project and add a Strongly Typed Dataset . Before creating a Strongly Typed take a look at the detailed tutorial of create a strongly typed datset and add five column in the Datatable. Here we are limiting as five column , but you can add any number of column according to your requirements. Next step is to create a Crystal Reports design from the Strongly Typed dataset. Select all the column from dataset. . Shared .NET.more Imports System. Public Function procesSQL() As String Put the following vb. So we create a function for parsing SQL statements.net source code in your form and run the program .SqlClient Imports CrystalDecisions.Data. Button and Crystal Reports Viewer .Engine Imports CrystalDecisions.vb) and add a TextBox . For that we parsing the SQL statement before we passing it to Crystal Reports. charts. but the ability to make good decisions is greatly enhanced by the ability to visualize data.CrystalReports. and models in Excel rather than hard to learn developer tools and you can easily deploy them with SpreadsheetGear for . Print Source Code SpreadsheetGear: Excel Charting Samples Richly formatted workbooks with fast and complete calculations are the heart and soul of a spreadsheet. Download Source Code Dashboards from Excel Charts and Ranges You and your users can design dashboards. reports.Select the default form(Form1. Here we are going to pass the SQl statements to Crystal Reports at runtime . (fromStart selectStart)) lastPart = inSql.ToString() Else firstPart = firstPart & fields(i).ToString() & _ " AS COLUMN" & i + 1 . " _ & fields(i).Click Dim cnn As SqlConnection Dim connectionString As String Dim sql As String connectionString = "data source=SERVERNAME.Open() sql = procesSQL() Dim dscmd As New SqlDataAdapter(sql.ReportSource = objRpt CrystalReportViewer1.Split(".ToString() & " + 1 AS COLUMN" & i MyText = CType(objRpt. "Product") objRpt. _ initial catalog=crystaldb.password=PASSWORD.Text inSql = inSql.ReportDefinition.IndexOf("FROM") selectStart = selectStart + 6 firstPart = inSql.") firstPart = "" For i = 0 To fields.IndexOf("SELECT") fromStart = inSql.Data Public Class Form1 Dim objRpt As New CrystalReport1 Private Sub Button1_Click(ByVal sender As System.Length .Refresh() End Sub Public Function procesSQL() As String Dim sql As String Dim inSql As String Dim firstPart As String Dim lastPart As String Dim selectStart As Integer Dim fromStart As Integer Dim fields As String() Dim i As Integer Dim MyText As TextObject inSql = TextBox1.SetDataSource(ds. ByVal e As System.Object.ReportObjects("Text" _ & i + 1). cnn) Dim ds As New DataSet1 dscmd.fromStart) fields = firstPart.ToUpper selectStart = inSql. TextObject) MyText.Substring(selectStart.Text = fields(i).Fill(ds.1 If i > 0 Then firstPart = firstPart & " .user id=sa." cnn = New SqlConnection(connectionString) cnn.Substring(fromStart.Imports System.EventArgs) Handles Button1. inSql.Length .Tables(1)) CrystalReportViewer1. ToString() End If Next sql = "SELECT " & firstPart & " " & lastPart Return sql End Function End Class .MyText = CType(objRpt.Text = fields(i).ReportObjects("Text" & _ i + 1). TextObject) MyText.ReportDefinition.
Copyright © 2024 DOKUMEN.SITE Inc.