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 System.IO;
using MySql.Data.MySqlClient;
using System.Diagnostics;
using CrystalDecisions.CrystalReports.Engine;
using Microsoft.VisualBasic;
namespace student
{
public partial class UserReport : Form
{
ClassConnectDB Connect = new ClassConnectDB();
public UserReport()
{
InitializeComponent();
}
private void btnReport_Click(object sender, EventArgs e)
{
Connect.ConnectDB();//ติดต่ฐานข้อมูล
String strSQL;
DataTable dt = null;
strSQL = "SELECT user_id,user_name,user_address,user_province";
strSQL += ",user_zipcode,user_mail,user_phone FROM user where user_id like '%" + txtId.Text + "%' ";
MySqlDataAdapter adapter;
MySqlCommand objCmd;
objCmd = new MySqlCommand(strSQL, Connect.objConn);//ประมวลผล
adapter = new MySqlDataAdapter(objCmd);//เก็บข้อมูลไว้ที่ data adapter
DataSet data = new DataSet();//สร้าง data set
adapter.Fill(data, "user");//เก็บข้อมูลไว้ใน data set
dt = data.Tables[0];
adapter = null;
Connect.DisConnectDB();//ปิดฐานข้อมูล
Connect.objConn = null;//กำหนดค่าว่างให้ตัวแปร objConn
ReportDocument rpt = new ReportDocument();
string directory = AppDomain.CurrentDomain.BaseDirectory;
// rpt.Load(directory +"\\UserCrystalReport.rpt");
rpt.Load("E:\\BCShop\\student\\Project\\student\\UserCrystalReport.rpt");
rpt.SetDataSource(dt);
this.crystalReportViewer1.ReportSource = rpt;
this.crystalReportViewer1.Refresh();
}
}
}
Tag : .NET, MySQL, Crystal Report, C#, VS 2008 (.NET 3.x)