dear all

am getting insert error, confirming my connectionstring is working properly and am working on vs2005

<appSettings>
<add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\data.mdb"/>
</appSettings>
===============

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


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

    }

    private void ExecuteInsert(string Firstname, string Lastname, string Password, string Repassword, string email, string question, string answer, string age, string gender, string mobile, string country, string  city, string occupation)

    {
        OleDbConnection sqlConn = new OleDbConnection(ConfigurationManager.AppSettings["ConnectionString"]);

        string strSQL = "INSERT INTO Logindls (Firstname, Lastname, Password, Repassword, email,question, answer, age, gender, mobile, country, city, occupation) VALUES "
                    + " (@Firstname,@Lastname,@Password,@Repassword, @email,@question, @answer, @age,@gender, @mobile, @country, @city, @occupation)";
        try
        {
            sqlConn.Open();
            OleDbCommand sqlCmd = new OleDbCommand(strSQL, sqlConn);
            OleDbParameter[] param = new OleDbParameter[13];

            //param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
            
            param[0] = new OleDbParameter("@Firstname", OleDbType.Char, 50);
            param[1] = new OleDbParameter("@Lastname", OleDbType.Char, 50);
            param[2] = new OleDbParameter("@Password", OleDbType.Char, 8);
            param[3] = new OleDbParameter("@Repassword", OleDbType.Char, 8);
            param[4] = new OleDbParameter("@email", OleDbType.Char, 50);
            param[5] = new OleDbParameter("@question", OleDbType.Char, 50);
            param[6] = new OleDbParameter("@answer", OleDbType.Char, 50);
            param[7] = new OleDbParameter("@age", OleDbType.Char, 50);
            param[8] = new OleDbParameter("@gender", OleDbType.Char, 50);
            param[9] = new OleDbParameter("@mobile", OleDbType.Char, 50);
            param[10] = new OleDbParameter("@country", OleDbType.Char, 50);
            param[11] = new OleDbParameter("@city", OleDbType.Char, 50);
            param[12] = new OleDbParameter("@occupation", OleDbType.Char, 50);

            param[0].Value = Firstname;
            param[1].Value = Lastname;
            param[2].Value = Password;
            param[3].Value = Repassword;
            
            param[4].Value = email;
            param[5].Value = question;
            param[6].Value = answer;
            param[7].Value = age;
            param[8].Value = gender;
            param[9].Value = mobile;
            param[10].Value = country;
            param[11].Value = city;
            param[12].Value = occupation;
        
            for (int i = 0; i < param.Length; i++)
            {
                sqlCmd.Parameters.Add(param[i]);
            }

            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.ExecuteNonQuery();
        }
        catch (System.Data.OleDb.OleDbException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);

        }
        finally
        {
            sqlConn.Close();
        }
    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        {
            if (txtUserPwd.Text == txtReUserPwd.Text)
            {
                //call the method to execute insert to the database
                ExecuteInsert(txtFirstName.Text, txtLastName.Text, txtUserPwd.Text, txtReUserPwd.Text, txtEmailid.Text, txtQuestion.Text, txtAnswer.Text, txtAge.Text, ddlGender.SelectedItem.Text, txtMobileNo.Text, ddlCountry.SelectedItem.Text, txtCity.Text, ddlOccupation.SelectedItem.Text);
                Response.Write("Record was successfully added!");
                ClearControls(Page);
            }
            else
            {
                Response.Write("Password did not match");
                txtUserPwd.Focus();
            }

        }
    }

    public static void ClearControls(Control Parent)
    {
        if (Parent is TextBox)
        { (Parent as TextBox).Text = string.Empty; }
        else
        {
            foreach (Control c in Parent.Controls)
                ClearControls(c);
        }
    }
}

Change the Paasword field in INSERT INTO Statement into some other name like UserPassword.
I'm not sure ,but give it a try

What is the exact error message you receive? It sounds like a datatype mismatch, truncated string, or something along those lines. The query syntax itself is OK. I verified it using:

create table Logindls
(
firstname varchar(1),
lastname varchar(1),
Password varchar(1),
Repassword varchar(1),
email varchar(1),
question varchar(1),
answer varchar(1),
age varchar(1),
gender varchar(1),
mobile varchar(1),
country varchar(1),
city varchar(1),
occupation varchar(1)
)

DeclarE @firstname varchar,
@lastname varchar,
@Password varchar,
@Repassword varchar,
@email varchar,
@question varchar,
@answer varchar,
@age varchar,
@gender varchar,
@mobile varchar,
@country varchar,
@city varchar,
@occupation varchar
INSERT INTO Logindls (Firstname, Lastname, Password, Repassword, email,question, answer, age, gender, mobile, country, city, occupation) 
VALUES (@Firstname,@Lastname,@Password,@Repassword, @email,@question, @answer, @age,@gender, @mobile, @country, @city, @occupation)

hi dear

yes, you right.
its solved and it was error due to password keyword which is reserved. I have changed it user_pass

thanx to all of you. its really a great forum. cheers
samir

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.