โดย Page แต่ละหน้า เรียกใช้ Class หมด ลองทดสอบบนเครื่อง สามารถใช้งานได้ปกติ
แต่พออัพขึ้น Host จริงๆ กลับมองไม่เห้น Class นี้ ทำยังไงดีคะ
Code (C#)
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'DBConnect' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 15: public partial class Index : System.Web.UI.Page
Line 16: {
Line 17: DBConnect DB = new DBConnect();
Line 18: bool isLogin = false;
Line 19:
Error แบบนี้ ตลอดเลยค่ะ !!
Code หน้า DBConnect คร่าวๆ Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
namespace ExpenseReport
{
public partial class DBConnect
{
private SqlConnection objConn;
private SqlCommand objCmd;
private SqlTransaction Trans;
private String strConnString;
private String strCommandString;
private static String empID;
private static String empName;
public DBConnect()
{
strConnString = ConfigurationManager.ConnectionStrings["Con"].ToString();
}
public SqlDataReader QueryDataReader(String strSQL)
{
SqlDataReader dtReader;
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
objCmd = new SqlCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
return dtReader; //*** Return DataReader ***//
}
public DataSet QueryDataSet(String strSQL)
{
DataSet ds = new DataSet();
SqlDataAdapter dtAdapter = new SqlDataAdapter();
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
objCmd = new SqlCommand();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds);
return ds; //*** Return DataSet ***//
}
public DataTable QueryDataTable(String strSQL)
{
SqlDataAdapter dtAdapter;
DataTable dt = new DataTable();
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
dtAdapter = new SqlDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
return dt; //*** Return DataTable ***//
}
}
}
ส่วนอันนี้โค้ดหน้า Index แบบคร่าวๆ
Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
namespace ExpenseReport
{
public partial class Index : System.Web.UI.Page
{
DBConnect DB = new DBConnect();
bool isLogin = false;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
IsCheck(txtUsername.Text, txtPassword.Text);
}
private void IsCheck(string username, string password)//ตรวจสอบค่าที่รับเข้ามา
{
string role = "";
string empName = "";
string empID = "";
string SQL = "SELECT empUsername, empPassword, empType, empID, empName FROM Employee WHERE empUsername = '" + username + "' AND empPassword = '" + password + "'";
DataSet ds;
ds = DB.QueryDataSet(SQL);
if (ds.Tables[0].Rows.Count > 0)
{
if (username == ds.Tables[0].Rows[0]["empUsername"].ToString())
{
if (password == ds.Tables[0].Rows[0]["empPassword"].ToString())
{
isLogin = true;
role = ds.Tables[0].Rows[0]["empType"].ToString();
empName = ds.Tables[0].Rows[0]["empName"].ToString();
empID = ds.Tables[0].Rows[0]["empID"].ToString();
}
else
{
isLogin = false;
}
}
else
{
isLogin = false;
}
}
else
{
isLogin = false;
}
if (isLogin)
{
MyTicket(username, role, empName, empID); //เรียกใช้ ticket
}
else
{
Label1.Text = "Login Failed";
}
}
}
}