using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls;

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

    }
    protected void btn_CreatingUserAccount_Click(object sender, EventArgs e)

        {
            InsertInfo();
        }

     private void InsertInfo()
    {

        SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2010\\Projects\\AZ\\App_Data\\SecurityTutorials.mdf;Integrated Security=True;User Instance=True");
        string sql = "INSERT INTO BuyerSignUp (UserName,Email,Pass,ConfirmPass,Type) VALUES ('@Val1','@Val2','@Val3','@Val4','@Val5')";
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@Val1", TxtUsername.Text);
            cmd.Parameters.AddWithValue("@Val2", TxtEmail.Text);
            cmd.Parameters.AddWithValue("@Val3", TxtUserPassword.Text);
            cmd.Parameters.AddWithValue("@Val4", TxtUserConfirmPassword.Text);
            cmd.Parameters.AddWithValue("@Val5", Dd_Type.SelectedItem);
            cmd.CommandType = CommandType.Text;

            if (TxtUserPassword.Text == TxtUserConfirmPassword.Text)
            {
           lblError.Text = "Your data has been inserted successfull......!";
                      cmd.ExecuteNonQuery();

            }
            else
            {
                lblError.Text = "Sorry, You didnt typed your password correctly.  Please type again.";
                lblError.Visible = true;
            }


        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);

        }
        finally
        {
            conn.Close();
        }
    }
}

Recommended Answers

All 2 Replies

can you please mention which error you are getting in this above mentioned code.

Don't put ' marks around @val1, etc in your SQL statement, the system will handle that for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.