ช่วยเหลือหน่อยนะค่ะ โค้ด login C# web app อ่ะค่ะ มาน eror
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
private string strcon1;
protected void Page_Load(object sender, EventArgs e)
{
strcon1 = Session["strcon"].ToString();
}
protected void btn_clear_Click(object sender, EventArgs e)
{
lbl_user.Visible = false;
lbl_passwd.Visible = false;
lbl_radio.Visible = false;
txt_user.Text = "";
txt_passwd.Text = "";
}
protected void btn_user_Click(object sender, EventArgs e)
{
if (txt_user.Text == "")
{
lbl_user.Visible = true;
}
else if (txt_passwd.Text == "")
{
lbl_passwd.Visible = true;
}
else if (radio_main.Checked)
{
SqlConnection conn = new SqlConnection(strcon1);
string sql = "SELECT citizen_id,f_name,l_name FROM [user] WHERE citizen_id='" + txt_user.Text + "' AND passwd='" + txt_passwd.Text + "'";
DataTable dt = new DataTable();
conn.Open();
SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
dap.Fill(dt);
conn.Close();
if (dt.Rows.Count >= 1)
{
string citizenid = dt.Rows[0]["citizen_id"].ToString();
//string fname = dt.Rows[1]["f_name"].ToString();
//string lname = dt.Rows[2]["l_name"].ToString();
Session["sess_citizenid"] = citizenid;
//Session["sess_fname"] = fname;
//Session["sess_lname"] = lname;
Response.Redirect("index.aspx");
}
else
{
lbl_text.Visible = true;
}
}
else if (radio_admin.Checked)
{
SqlConnection conn = new SqlConnection(strcon1);
string sql = "SELECT ad_id FROM td_admin WHERE ad_username='" + txt_user.Text + "' AND ad_password='" + txt_passwd.Text + "'";
DataTable dt = new DataTable();
conn.Open();
SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
dap.Fill(dt);
conn.Close();
if (dt.Rows.Count >= 1)
{
string admin_id = dt.Rows[0]["ad_id"].ToString();
Session["sess_adminid"] = admin_id;
Response.Redirect("index.aspx");
}
else
{
lbl_text.Visible = true;
}
}
}
}
ลองดูนะครับ แต่ตัวนี้ผมเขียน ASP.net แต่เขียนแบบ C# หน้าจะเหมื่อนกันนะ
Date :
2009-08-06 10:08:16
By :
loogway
Load balance : Server 04