เออที่ string directory = My.Application.Info.DirectoryPath
ว่า Error 1 The name 'My' does not exist in the current context
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 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_name 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();
//เออเรอที่ำว่า My ครับ
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();
}
}
}
Tag : .NET, MySQL, Crystal Report, Win (Windows App), C#, VS 2008 (.NET 3.x)