IntroductionYou can get the first steps in developing with PostgreSQL using tutorial "Using PostgreSQL from Microsoft.NET" by John Charles OlamendyI used here Npgsql.Net provider to connect to PostgreSQLGetting started with the solutionI want here to show reports from postgreSQL using DataSet that can connect to any DB as Crystal Report only has a limited DataSourcesI assumed that you have DB with 2 tables users & carsUsing the codeCreating DatasetCreate dateset DataSetGeo using Right Click Solution Explorer -> Add -> Add New Item -> choose DataSet under the Categories then create DataTable called "CarsDT" contains the columns as in the figureCreating reportRight Click Solution Explorer -> Add -> Add New Item -> choose Crystal ReportStandard->from available datasources choose (Project Data-ADO.Net DataSets-DataSetGeo-CarsDT) then move it to selected tablesMove all available fields to fields to displayCreate Connection to PostgreSQLI create "BaseDAO" class that can handle all communications between your application & PostgreSQL
public void connect2DB() { npgConnection = new NpgsqlConnection("Server=localhost;UID=postgres;PWD=123;Database=GeoWebsite;Port=5432;"); } public DataTable SelectionQuery(string query) { npgConnection.Open(); IDbDataAdapter daPgsql = new Npgsql.NpgsqlDataAdapter(query, npgConnection); DataSet dsPg = new DataSet(); daPgsql.Fill(dsPg); DataTable dtPg = dsPg.Tables[0]; npgConnection.Close(); return dtPg; }
public Form1() { InitializeComponent(); myBaseDAO.connect2DB(); DataTable DTUsers = myBaseDAO.SelectionQuery("Select username from \"NonGeometrySchema\".users"); for (int i = 0; i < DTUsers.Rows.Count; i++) { cmbUsers.Items.Add((string)DTUsers.Rows[i][0]); } }
CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument; private void cmbUsers_SelectedValueChanged(object sender, EventArgs e) { myReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); DataTable myDT = myBaseDAO.SelectionQuery("Select cardrivername,cardrivermob,gpsno,carname,carmotorcc,carfuelrate,carcode from \"NonGeometrySchema\".cars WHERE userid = (SELECT userid from \"NonGeometrySchema\".users as users where users.username='" + cmbUsers.SelectedItem.ToString() + "')"); myReportDocument.Load(@"E:\CrystalReportWithPotsgreSQL\CrystalReportWithPotsgreSQL\Reports\ReportCarsOfSpecifiedUser.rpt"); myReportDocument.SetDataSource(myDT); crystalReportViewer1.ReportSource = myReportDocument; crystalReportViewer1.Refresh(); }
Crystal and Reporting Services FAQ - Part 2
Crystal Reports: 3 New Uses For Sub Reports
I would like to create a connection from the crystal report to a PostgreSQL do you know the steps? not through the .NET