Click here to Skip to main content
16,021,294 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Data.SqlClient;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private Boolean InsertUpdateData(SqlCommand cmd)
    {
        String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["lateefConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            return true;
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
            return false;
        }
        finally
        {
            con.Close();
            con.Dispose();
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

   //   using(SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["lateefConnectionString"].ConnectionString))
        {
            try
            {
                string strQuery = "INSERT INTO [Register],[firstname],[lastname],[email],[Password],[Gender],[Dob],[Mobile],[department],[Address]) VALUES (@firstname,@lastname,@email,@Password,@Gender,@Dob,@Mobile,@department,@Address)";

                SqlCommand cmd = new SqlCommand(strQuery);

                //            const string SQL = "INSERT INTO Register values(@firstname,@lastname,@email,@Password,@Gender,@Dob,@Mobile,@department,@Address)";

                //adding parameters with value
                cmd.Parameters.AddWithValue("@firstname", txtFirstName.Text.ToString());
                cmd.Parameters.AddWithValue("@lastname", txtLastName.Text.ToString());
                cmd.Parameters.AddWithValue("@lastname", txtEmail.Text.ToString());
                cmd.Parameters.AddWithValue("@password", txtPassword.Text.ToString());
                cmd.Parameters.AddWithValue("@Gender", RdoGender.SelectedItem.Text.ToString());
                cmd.Parameters.AddWithValue("@Dob", txtDob.Text.ToString());
                cmd.Parameters.AddWithValue("@Mobile", txtMobile.Text.ToString());
                cmd.Parameters.AddWithValue("@department", TxtDpt.Text.ToString());
                cmd.Parameters.AddWithValue("@Address", txtAddress.Text.ToString());
                InsertUpdateData(cmd);

                lblMsg.Text= "Submission successful with Track ID";
            }
            catch
            {
            //  lblMsg.Text = "Not successful.";

            }
        }
    }
}
Posted
Comments
[no name] 21-Jul-14 8:28am    
First off. This is a code dump. It is not a question or a description of any problem.
Why are you converting strings to strings? They are already strings, there is no real need to convert strings to strings.
Empty catch blocks are useless. You are just throwing away information.
Why are you inserting @lastname twice? You need to look your parameter list again.... CAREFULLY.

You are getting an error but because your catch is empty you aren't seeing it. Your insert statement is not correct. Do this instead..

SQL
INSERT INTO tableName (field1, field2)
VALUES (@value1, @value2)
 
Share this answer
 
Change your query from

string strQuery = "INSERT INTO [Register],[firstname],[lastname],[email],[Password],[Gender],[Dob],[Mobile],[department],[Address]) VALUES (@firstname,@lastname,@email,@Password,@Gender,@Dob,@Mobile,@department,@Address)";

To

string strQuery = "INSERT INTO ([Register],[firstname],[lastname],[email],[Password],[Gender],[Dob],[Mobile],[department],[Address]) VALUES (@register,@firstname,@lastname,@email,@Password,@Gender,@Dob,@Mobile,@department,@Address)";

you are missing "(" bracket and @register parameter.
 
Share this answer
 
v2

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