|
|
|
มันไม่ตรวจสอบ user แล้วไม่ลงฐานข้อมูล แก้ไง ใครมีวิธีแนะนำหน่อย |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Web.Configuration;
using System.Data.SqlClient;
using System.Text;
public partial class registermember : System.Web.UI.Page
{
//private Sub autoMember_ID();
private string strConn;
private string strSql;
private SqlCommand cmd;
private SqlConnection conn;
SqlConnection Conn = new SqlConnection();
SqlCommand Cmd = new SqlCommand();
string sqlStr;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
strConn = WebConfigurationManager.ConnectionStrings["casio1"].ConnectionString;
Conn.ConnectionString = strConn;
Conn.Open();
this.Label3.Visible = true;
}
protected void bsave_Click(object sender, EventArgs e)
{
string strSQL, strConn = "Data Source = COMPUTER-PC;Initial Catalog=Casio1;Integrated Security=true";
Conn = new SqlConnection();
if (Conn.State == ConnectionState.Open)
{
this.Label3.Text = "ผิดพลาดมีปัญหาในการเชื่อมต่อฐานข้อมูล";
//label1.Show("ผิดพลาดมีปัญหาในการเชื่อมต่อฐานข้อมูล", "ระบบผิดพลาด");
}
else
{
Conn.ConnectionString = strConn;
Conn.Open();
DataSet dat = new DataSet();
SqlCommand cmd;
int intNumRows = 0;
strSQL = "SELECT COUNT (user_mem) FROM Member WHERE user_mem ='" + this.tuser.Text + "'";
cmd = new SqlCommand(strSQL, Conn);
intNumRows = Convert.ToInt32(cmd.ExecuteScalar());
if (intNumRows > 0)
{
this.pnlAdd.Visible = false;
this.Label3.Visible = true;
this.Label3.Text = "Username already exists.";
}
else
{
if ((RadioButton1.Checked == true))
{
sqlStr = "INSERT INTO Member (user_mem,password_mem,idcard_mem,name_mem,surname_mem,brith_mem,gender_mem) " + " VALUES " + " ('" + this.tuser.Text + "','" + this.tpass.Text + "','" + this.tcard.Text + "','" + this.tname.Text + "','" + this.tsurname.Text + "','" + this.tbirth.Text + "','" + this.RadioButton1.Text + "')";
}
else
{
sqlStr = "INSERT INTO Member (user_mem,password_mem,idcard_mem,name_mem,surname_mem,brith_mem,gender_mem,career_mem) " + " VALUES " + " ('" + this.tuser.Text + "','" + this.tpass.Text + "','" + this.tcard.Text + "','" + this.tname.Text + "','" + this.tsurname.Text + "','" + this.tbirth.Text + "','" + this.RadioButton2.Text + "','" + this.ddl_career.Text + "')";
}
//sqlStr = "INSERT INTO member(user_mem,password_mem,date_mem, , address_mem, province_mem, postal_mem, phone_mem, email_mem)" + " VALUES " + "('" + this.tuser.Text+ "','" + this.tpass.Text+ "','" + this.tcard.Text+ "','" + this.ldate.Text+ "','" + this.tb_address.Text+ "', '" + this.tbpostal.Text+ "','" + this.tbphone.Text+ "','" + this.temail.Text+ "')";
//cmd.Parameters.Add("@province_mem", SqlDbType.VarChar).Value = ddlprovice.Text.Trim();
//if (RadioButton1.Checked == true)
//{
// cmd.Parameters.Add("@gender_mem", SqlDbType.VarChar).Value = "ชาย";
//}
//else
//{
// cmd.Parameters.Add("@gender_mem", SqlDbType.VarChar).Value = "หญิง";
//}
Cmd = new SqlCommand();
{
Cmd.Connection = Conn;
Cmd.CommandText = sqlStr;
Cmd.CommandType = CommandType.Text;
}
this.pnlAdd.Visible = false;
try
{
Cmd.ExecuteNonQuery();
this.Label3.Text = "Register Sucessful.";
this.Label3.Visible = true;
}
catch (Exception ex)
{
this.Label3.Visible = true;
this.Label3.Text = "Cannot Register : Error (" + ex.Message + ")";
}
}
Conn.Close();
Conn = null;
}
}
}
Tag : ASP.NET, C#
|
|
|
|
|
|
Date :
2011-08-16 21:17:26 |
By :
mod0882 |
View :
1071 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขึ้น Error อะไรบ้างครับ
|
|
|
|
|
Date :
2011-08-17 06:27:22 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|