1 Replies - 1112 Views - Last Post: 10 October 2013 - 03:24 PM Rate Topic: -----

#1 NightFire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-October 13

Registration page error in .NET

Posted 10 October 2013 - 02:56 PM

i'm a newbie in .NET and C# field. I'm creating a Registration page to a website im working on. i keep getting an error when registering to a website i'm creating. When entering my details, it doesn't register me to the database. I created the a table in the database(i created a connectionString), and yet i cannot register - i get an exception that says "error,please try registering again" (as i did). Does someone know what am i doing wrong?! Thanks!

here's my code and images:

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 Registration : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from Table where Username='" + TextBox1Username.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
// int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
con.Close();
/* if (temp == 1)
{
Response.Write("username already exists");
} */
}
}


protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}


protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr ing);
con.Open();
string insCmd = "Insert into Table (Username, Password, EmailAddress,Fullname, City) values (@Username, @Password, @EmailAddress, @Fullname, @City)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@Username", TextBox1Username.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBox4Email.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@City", TextBox6City.Text);

try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
Response.Write("error,please try registering again");
}

}



i'm a newbie in .NET and C# field. I'm creating a Registration page to a website im working on. i keep getting an error when registering to a website i'm creating. When entering my details, it doesn't register me to the database. I created the a table in the database(i created a connectionString), and yet i cannot register - i get an exception that says "error,please try registering again" (as i did). Does someone know what am i doing wrong?! Thanks!

here's my code and images:

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 Registration : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from Table where Username='" + TextBox1Username.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
// int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
con.Close();
/* if (temp == 1)
{
Response.Write("username already exists");
} */
}
}


protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}


protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr ing);
con.Open();
string insCmd = "Insert into Table (Username, Password, EmailAddress,Fullname, City) values (@Username, @Password, @EmailAddress, @Fullname, @City)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@Username", TextBox1Username.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBox4Email.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@City", TextBox6City.Text);

try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
Response.Write("error,please try registering again");
}

}
}

A link to the image:
http://imageshack.us...ges/4/os6b.jpg/

Is This A Good Question/Topic? 0
  • +

Replies To: Registration page error in .NET

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2877
  • View blog
  • Posts: 9,548
  • Joined: 12-December 12

Re: Registration page error in .NET

Posted 10 October 2013 - 03:24 PM

You are supplying @Password twice, rather than @Fullname.

BTW During development you would be better off outputting the error message from the er object rather than just "error,please try registering again". The error message would tell you that you haven't supplied one of the parameters.

BTWW Is your table seriously named Table?! :surrender:

This post has been edited by andrewsw: 10 October 2013 - 03:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1