|
|
|
ออก Crystal report datatable dataset ใช้ database access |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using System.Data.OleDb;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void tb1BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.tb1BindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.database3DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'database3DataSet.tb1' table. You can move, or remove it, as needed.
this.tb1TableAdapter.Fill(this.database3DataSet.tb1);
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
OleDbConnection objConn = new OleDbConnection();
OleDbCommand objCmd = new OleDbCommand();
OleDbDataAdapter dtAdapter = new OleDbDataAdapter();
DataSet ds = new DataSet();
DataTable dt = null;
string strConnString = null;
string strSQL = null;
strConnString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C: \Users\Peerakit\Documents\Visual Studio 2015\Projects\WindowsFormsApplication13\WindowsFormsApplication13\bin\x86\Debug\Database3.accdb";
strSQL = "SELECT * FROM tb1 WHERE ID = '" + this.toolStripTextBox1.Text + "' ";
objConn.ConnectionString = strConnString;
var _with1 = objCmd;
_with1.Connection = objConn;
_with1.CommandText = strSQL;
_with1.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds, "myDataTable");
dt = ds.Tables[0];
dtAdapter = null;
objConn.Close();
objConn = null;
ReportDocument rpt = new ReportDocument();
//string directory = My.Application.Info.DirectoryPath;
//rpt.Load(directory & "\\myCrystalReport1.rpt")
//rpt.Load("C:\\DemoCrystalReport2\\DemoCrystalReport2\\myCrystalReport1.rpt");
rpt.SetDataSource(dt);
this.crystalReportViewer1.ReportSource = rpt;
this.crystalReportViewer1.Refresh();
}
}
}
อ้างอิงจาก บทความ
https://www.thaicreate.com/dotnet/crystal-report-dataset-datatable.html
Tag : .NET, Ms Access, Crystal Report, Win (Windows App), C#, Windows
|
|
|
|
|
|
Date :
2016-12-04 18:16:57 |
By :
snowman0020 |
View :
837 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-12-04 18:20:55 |
By :
snowman0020 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|