using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registeration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionstring"].ConnectionString);
conn.Open();
string chkUser = "SELECT Count(*) from userData WHERE userName='" + textBoxUsername.Text + "'";
SqlCommand cmd = new SqlCommand(chkUser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already exists.");
}
conn.Close();
}
}
protected void bntSubmit_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionstring"].ConnectionString);
conn.Open();
string insertQuery = "INSERT INTO userData(userName,Email,Password,Country) VALUES(@Uname ,@email ,@password ,@country)";
SqlCommand cmd = new SqlCommand(insertQuery,conn);
cmd.Parameters.AddWithValue("@Uname", textBoxUsername.Text);
cmd.Parameters.AddWithValue("@email", TextBoxEmail.Text);
cmd.Parameters.AddWithValue("@password", TextBoxPassword.Text);
cmd.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem);
cmd.ExecuteNonQuery();
Response.Redirect("manager.aspx");
Response.Write("Inserted Into Database.");
conn.Close();
}
catch (Exception ex)
{
Response.Write("ERROR:" + ex.ToString());
}
}
protected void textBoxUsername_TextChanged(object sender, EventArgs e)
{
}
}
error ตรงไหน ครับ C# ASP.NET
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registeration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionstring"].ConnectionString);
conn.Open();
string chkUser = "SELECT Count(*) from userData WHERE userName='" + textBoxUsername.Text + "'";
SqlCommand cmd = new SqlCommand(chkUser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already exists.");
}
conn.Close();
}
}
protected void bntSubmit_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionstring"].ConnectionString);
conn.Open();
string insertQuery = "INSERT INTO userData(userName,Email,Password,Country) VALUES(@Uname ,@email ,@password ,@country)";
SqlCommand cmd = new SqlCommand(insertQuery,conn);
cmd.Parameters.AddWithValue("@Uname", textBoxUsername.Text);
cmd.Parameters.AddWithValue("@email", TextBoxEmail.Text);
cmd.Parameters.AddWithValue("@password", TextBoxPassword.Text);
cmd.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem);
cmd.ExecuteNonQuery();
Response.Redirect("manager.aspx");
Response.Write("Inserted Into Database.");
conn.Close();
}
catch (Exception ex)
{
Response.Write("ERROR:" + ex.ToString());
}
}
protected void textBoxUsername_TextChanged(object sender, EventArgs e)
{
}
}