Good Afternoon All

i think its Firday fever, am tired. I think this Happens sometimes. let me get to the Problem. Am doing an OleDb Project

I have an Access DB and the table is Users , here are the Field and dataType

ID = Autonumber(int)
Firstname = TEXT
LastName = TEXT
Username = TEXT
Password = TEXT
Email = TEXT

Now i have a Function that inserts into these Field from my DAL that is Written like this

public int Register_User(String Firstname, String LastName, String Username, String Password, String Email)
            int Res=0;
            con = new OleDbConnection(strcon);

            cmdinsert = new OleDbCommand();

            cmdinsert.CommandText = "insert into Users Values(?,?,?,?,?)";

            cmdinsert.CommandTimeout = 0;

            cmdinsert.CommandType = CommandType.Text;

            cmdinsert.Connection = con;

            cmdinsert.Parameters.Add("Username", OleDbType.VarChar,30).Value = Convert.ToString(Username);

            cmdinsert.Parameters.Add("Password", OleDbType.VarChar,30).Value = Convert.ToString(Password);

            cmdinsert.Parameters.Add("Firstname", OleDbType.VarChar,30).Value = Convert.ToString(Firstname);

            cmdinsert.Parameters.Add("LastName", OleDbType.VarChar,30).Value = Convert.ToString(LastName);

            cmdinsert.Parameters.Add("Email", OleDbType.VarChar, 30).Value = Convert.ToString(Email);


                Res =(int) cmdinsert.ExecuteScalar();

            catch (OleDbException)
                 return Res;

When i try to insert , i get an Exception.

Number of query values and destination fields are not the same.

Can you please Point the Problem for me

Thank you :)

Recommended Answers

All 3 Replies

specify the fields in the insert query

insert into Users (FirstName, LastName, ...etc)

yep or, allow for all the fields in the table.

Thanks Man it helped

Be a part of the DaniWeb community

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