Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<%@ Page Language="VB" %>
<script runat="server">
Protected Void Submit_Click(object sender, EventArgs e)
{

SqlDataReader dr;
SqlConnection conn = new SqlConnection(@"Data Source=ISPAT-1F5391CA3;Username="ISPAT-1F5391CA3\Administrator";password="";Initial Catalog=MyDatabase;Integrated Security=SSPI;");
      SqlCommand cmd1 = new SqlCommand();
      SqlCommand cmd2 = new SqlCommand();
    /* Check whether LoginId already exist or not. */
     cmd2.CommandText = "Select * from User_Profile where LoginId='" +Loginid.Text + "'";
     cmd2.Connection = conn;
    conn.Open();
dr = cmd2.ExecuteReader();
            if (!dr.Read())
    {
         cmd1.CommandText = "INSERT INTO User_Profile values('" + Loginid.Text + "','"+ Pwd.Text + "','" + Fname.Text + "','"+ Lname.Text + "','" + Gender.SelectedValue + "','" + Email.Text + "','"+DateTime.Now.ToString()+"','"                               +Sec_Ques.Text+"','"+Sec_Ans.Text+"')";            cmd1.Connection = conn;
   cmd1.ExecuteNonQuery();
      conn.Close();
      Msg.Text = "Record successfully updated!!!!!";
         Response.Redirect("default.aspx");
     }
 else
    Msg.Text = "Please choose a different Login Id";
         dr.Close();
  conn.Close();
   }
</script>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
  </form>
  <!--webbot bot="SaveResults" u-file="C:\Documents and Settings\Administrator\Desktop\reg\_private\form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" --><table class="style1">
           <tr>
                <td>
                    Login:</td>
                <td>
                    <asp:TextBox ID="TxtName" runat="server">
                    <input type="text" name="T1" size="20"></asp:TextBox></td>
                    <asp:RangeValidator ControlToValidate="TxtName" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />
            </tr>
            <tr>
                <td>
                    Password:</td>
                <td>
                    <asp:TextBox ID="TxtPassword"  TextMode="Password" runat="server">
                    <input type="text" name="T2" size="20"></asp:TextBox></td>
           </tr>
            <tr>
                <td>
                   First Name:</td>
                <td>
            <asp:TextBox ID="TxtFname" runat="server">
            <input type="text" name="T3" size="20"></asp:TextBox></td>
            <asp:RangeValidator ControlToValidate="TxtFname" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />
          </tr>
            <tr>
                <td>
                    Last Name:</td>

                <td>
            <asp:TextBox ID="TxtLname" runat="server">
            <input type="text" name="T4" size="20"></asp:TextBox></td>
           <asp:RangeValidator ControlToValidate="TxtLname" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />
            </tr>
            <tr>
                <td>
                    Gender:</td>
                <td>
                    <select size="1" name="D1">
                <option>Male</option>
                <option>Female</option>
                </select></td>
            </tr>
            <tr>
                <td>
                    Email:</td>
                <td>
                <asp:TextBox ID="TxtEmail" runat="server">
            <input type="text" name="T5" size="20"></asp:TextBox></td>
           <asp:RangeValidator ControlToValidate="TxtEmail" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />
            </tr>
            <tr>
                <td>
                    Date:</td>
                <td>
             <asp:TextBox ID="TxtDate" runat="server">
            <input type="text" name="T6" size="20"></asp:TextBox></td>
           <asp:RangeValidator ControlToValidate="TxtDate" MinimumValue="2010-01-01" MaximumValue="2010-12-31" Type="Date" EnableClientScript="false" Text="Invalid Date!" runat="server" />
            </tr>
            </table>
        <asp:Button ID="Submit" text="submit" runat="server" Text="Save" OnClick="Submit_Click" />
    <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
Posted
Comments
Ankur\m/ 6-Jul-10 2:24am    
Would you mind specifying the error details?

Forget about error in application.

Lots of things are wrong in your code. Important ones:
1. You have a Response.Redirect while reading a file when connection is Open!
2. Your way to validate a particular user as a valid user (using username, password) is also not right.

First thing I would suggest to you is to read about ADO.NET before coding.
MSDN: ADO.NET[^]
 
Share this answer
 
Comments
Ankur\m/ 6-Jul-10 2:41am    
To add more,
Using query in your code is not a good practice from security point of view. It is vulnerable to SQL Injection. Always use Stored Procedure. It is safe and has better performance.
Okay can u give me a simple code for registration form

or

jst correct the above code.

Thanks.......
 
Share this answer
 

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