|
|
|
สอบถามเรื่องการกำหนดสิทธิการเข้าใช้งานตอน Login ASP.NET(C#) หน่อยครับ |
|
|
|
|
|
|
|
พอดีผมทำ Login แบบกำหนดสิทธิ์ได้แล้ว แล้วก็ Login แบบกำหนดสิทธิ์ได้แล้ว
แต่ติดปัญหาคือ เวลา Login แบบ Username&Password ไม่ถูกต้อง เกิด Error ขึ้นตามรูป
จะต้องแก้ไขยังไงบ้างครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public partial class frmLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection objConn = null;
string strConnString = null;
StringBuilder strSQL = default(StringBuilder);
SqlCommand objCmd = null;
int intCount = 0;
//*** Open Connection ***'
strConnString = @"Data Source=PANPOO-PC\SQLEXPRESS;Initial Catalog=C:\PROJECT\TEST2\APP_DATA\DATABASE.MDF;Integrated Security=True";
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
//*** Check Login ***'
strSQL = new StringBuilder();
strSQL.Append(" SELECT roleID FROM Member ");
strSQL.Append(" WHERE Username = @sUsername ");
strSQL.Append(" AND Password = @sPassword ");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = this.txtUsername.Text;
objCmd.Parameters.Add("@sPassword", SqlDbType.VarChar).Value = this.txtPassword.Text;
intCount = (int)objCmd.ExecuteScalar();
objConn.Close();
objConn = null;
if (intCount <= 0)
{
this.lblStatus.ForeColor = System.Drawing.Color.Red;
this.lblStatus.Text = "Username or Password wrong!";
}
else if (intCount == 1)
{
Session["strUsername"] = this.txtUsername.Text;
Response.Redirect("frmAdmin.aspx");
}
else if (intCount == 2)
{
Session["strUsername"] = this.txtUsername.Text;
Response.Redirect("frmEmployee.aspx");
}
else if (intCount == 3)
{
Session["strUsername"] = this.txtUsername.Text;
Response.Redirect("frmMember.aspx");
}
}
}
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), WebService, C#, VS 2008 (.NET 3.x)
|
|
|
|
|
|
Date :
2012-08-14 18:29:04 |
By :
panpoo |
View :
1850 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีค่าใดค่าหนึ่งว่างหรือเปล่าครับ ผมดูจากที่เขียน ๆ ไว้แล้วก็น่าจะครบแล้วน่ะ
Code (C#)
SqlConnection objConn = new SqlConnection();
string strConnString = null;
string strSQL = null;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
strSQL = "INSERT INTO files (Name,FilesName,FilesType) VALUES (@sName,@sFilesName,@sFilesType)";
objConn.ConnectionString = strConnString;
objConn.Open();
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
objCmd.Parameters.Add("@sName", SqlDbType.Binary).Value = this.txtName.Text;
objCmd.Parameters.Add("@sFilesName", SqlDbType.VarChar).Value = imbByte;
objCmd.Parameters.Add("@sFilesType", SqlDbType.Int).Value = strMIME;
objCmd.ExecuteNonQuery();
objConn.Close();
objConn = null;
|
|
|
|
|
Date :
2012-08-15 11:41:04 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|