อยากให้มันใส่ ID อัตโนมัติ ที่เพิ่มค่าทีละ1ในดาต้าเบส แล้วก็เช็ค User กับ Email จากดาต้าเบสอะครับ
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 Design : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtPassword_TextChanged(object sender, EventArgs e)
{
}
protected void txtUser_TextChanged(object sender, EventArgs e)
{
}
protected void txtConfirmPassword_TextChanged(object sender, EventArgs e)
{
}
protected void txtFirstName_TextChanged(object sender, EventArgs e)
{
}
protected void txtLastName_TextChanged(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
}
protected void txtAge_TextChanged(object sender, EventArgs e)
{
}
protected void txtBirthDate_TextChanged(object sender, EventArgs e)
{
}
protected void txtAddress_TextChanged(object sender, EventArgs e)
{
}
protected void txtTel_TextChanged(object sender, EventArgs e)
{
}
protected void txtEmail_TextChanged(object sender, EventArgs e)
{
}
protected void txtConfirmEmail_TextChanged(object sender, EventArgs e)
{
}
protected void btnRegister_Click(object sender, EventArgs e)
{
//-------------------Insert SQL----------------------------
try
{
string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
string commandText = @"insert into Userdata (ID,nUser,Password,Firstname,Lastname,Sex,Age,Birthdate,Address,Tel,Email)
values ('2',@nUser,@Password,@Firstname,@Lastname,@sex,@Age,@Birthdate,@Address,@Tel,@Email)";
SqlCommand comm = new SqlCommand(commandText, conn);
conn.Open();
if (txtUser.Text.Length < 6)
{
string myscript = "alert ('กรุณาใส่ Username ระหว่าง 6 - 12 ตัวด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtUser.Text.Length > 12)
{
string myscript = "alert ('กรุณาใส่ Username ระหว่าง 6 - 12 ตัวด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtPassword.Text.Length < 6)
{
string myscript = "alert ('กรุณาใส่ Password ระหว่าง 6 - 12 ตัวด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtPassword.Text.Length > 12)
{
string myscript = "alert ('กรุณาใส่ Password ระหว่าง 6 - 12 ตัวด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtPassword.Text != txtConfirmPassword.Text)
{
Response.Write("<script>alert('กรุณากรอก Password ให้ตรงกันด้วยค่ะ ...')</script>");
}
else if (txtFirstName.Text.Length == 0)
{
string myscript = "alert ('กรุณาใส่ ชื่อ ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtLastName.Text.Length == 0)
{
string myscript = "alert ('กรุณาใส่ นามสกุล ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtAge.Text.Length == 0)
{
string myscript = "alert ('กรุณาใส่ อายุ ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtBirthDate.Text.Length == 0)
{
string myscript = "alert ('กรุณาใส่ วันเกิด ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtEmail.Text.Length == 0)
{
string myscript = "alert ('กรุณาใส่ อีเมล ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtConfirmEmail.Text.Length == 0)
{
string myscript = "alert ('กรุณายืนยัน อีเมล ด้วยค่ะ...');";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myscript, true);
}
else if (txtEmail.Text != txtConfirmEmail.Text)
{
Response.Write("<script>alert('กรุณากรอก Email ให้ตรงกันด้วยค่ะ ...')</script>");
}
else
{
comm.Parameters.Add("@nUser", SqlDbType.VarChar).Value = txtUser.Text.Trim();
comm.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtPassword.Text.Trim();
comm.Parameters.Add("@Firstname", SqlDbType.VarChar).Value = txtFirstName.Text.Trim();
comm.Parameters.Add("@Lastname", SqlDbType.VarChar).Value = txtLastName.Text.Trim();
comm.Parameters.Add("@Sex", SqlDbType.VarChar).Value = RadioButtonList1.Text.Trim();
comm.Parameters.Add("@Age", SqlDbType.VarChar).Value = txtAge.Text.Trim();
comm.Parameters.Add("@Birthdate", SqlDbType.VarChar).Value = txtBirthDate.Text.Trim();
comm.Parameters.Add("@Email", SqlDbType.VarChar).Value = txtEmail.Text.Trim();
comm.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtAddress.Text.Trim();
comm.Parameters.Add("@Tel", SqlDbType.VarChar).Value = txtTel.Text.Trim();
}
comm.ExecuteNonQuery();
conn.Close();
Response.Write("Register Succesfully..");
Response.Redirect("Succesfully.aspx");
}
}
catch (Exception ex)
{
Response.Write("");
}
}
//----------------------------------------------------------------------------------
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Tag : - - - -
Date :
2009-03-17 19:04:14
By :
nongbreesh
View :
1722
Reply :
1
กำหนดฟิวส์เป็นแบบ Auto Number น่ะครับ
Date :
2009-03-19 06:37:05
By :
webmaster
Load balance : Server 01