Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,
I'm a newbie to ASP.NET
I want to make a registration form for my website, and I don't know why it's not working. when I enter user's information and click submit, it does nothing.

here is my code:
C#
 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 AdminUser : System.Web.UI.Page
{
    string StrConnect = ConfigurationManager.ConnectionStrings["WebUserDBConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void button1_Click(object sender, EventArgs e)
    {
        string strPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.Trim(), "md5");
        SqlConnection conn = new SqlConnection(StrConnect);
        try
        {
            conn.Open();
            string cmdText = "insert into Users values('"
                               + name.Text.Trim() + "','"
                               + strPwd + "','"
                               + TextBox3.Text.Trim() + "','"
                               + sex.SelectedItem.Text.Trim() + "','"
                               + Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
                               + TextBox4.Text + "','"
                               + DropDownList4.SelectedItem.Text + "','"
                               + TextBox5.Text + "',"
                               + "getdate()"
                               + ")"
                               ;
            SqlCommand comm = new SqlCommand(cmdText, conn);
            int nResult;
            nResult = comm.ExecuteNonQuery();
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + name.Text + ",Registration successful !!!" + "')</script>");
        }
        catch (SqlException ex)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + ex.Message + "')</script>");
        }
        finally
        {
            conn.Close();
        }
    }
    protected void button2_Click(object sender, EventArgs e)
    {

    }
}
Posted
Comments
Naga Sindhura 22-Apr-14 6:02am    
Hi, As per understanding you are getting error, please try to debug your code and identify the error. Check your password length because you are convert it to hash and then you are saving. Your code is Working for me.. :)

For better understanding
Try this first[^]
And then
try this[^]
 
Share this answer
 
v2
Comments
Member 10704121 22-Apr-14 7:05am    
thank you, I will read the articles
string cmdText = "insert into Users values('"
+ name.Text.Trim() + "','"
+ strPwd + "','"
+ TextBox3.Text.Trim() + "','"
+ sex.SelectedItem.Text.Trim() + "','"
+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
+ TextBox4.Text + "','"
+ DropDownList4.SelectedItem.Text + "','"
+ TextBox5.Text + "',"
+ "getdate()"
+ ")"
;



getdate() !!! i think you are inserting String into dateTime :D
you can use DateTime.Now instead

try this



string cmdText = "insert into Users values('"
+ name.Text.Trim() + "','"
+ strPwd + "','"
+ TextBox3.Text.Trim() + "','"
+ sex.SelectedItem.Text.Trim() + "','"
+ Convert.ToDateTime(DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.Text + "-" + DropDownList3.SelectedItem.Text) + "','"
+ TextBox4.Text + "','"
+ DropDownList4.SelectedItem.Text + "','"
+ TextBox5.Text + "',"
+ DateTime.Now
+ ")"
;
 
Share this answer
 
Comments
Naga Sindhura 22-Apr-14 6:56am    
getdate()is not a problem that is working fine for me.
HiiMa MhMhd 22-Apr-14 7:00am    
plz provide me with exception or the error you get
HiiMa MhMhd 22-Apr-14 7:04am    
implement this code again in new button the event handler might be proken
Member 10704121 22-Apr-14 7:13am    
I tried that but nothing changed, the thing is, when i enter the user info and click submit, it should show the message "registration successful" and add the new user to the database, nothing of these happens, and it doesnt give any error messages, just the registration form with no changes.
Naga Sindhura 22-Apr-14 7:34am    
please try to do debug, then you will know exact reason. However whatever you saying is correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900