0

im taking too much time for this error and can't find the error here

Adapter = New MySqlDataAdapter("Insert into tbluser(UserID,Name,UserType,Password) values('" & txtUserId.Text & "' ,'" & txtName.Text & "','" & cmbUserType.Text & "','" & "',AES_ENCRYPT('" & txtpass.Text & "','x'))", connection)
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Mark
  • 11
  • 5
  • 1
    a) you are wide open to SQL injection b) never, ever store the password - hash it instead; also looks like a datatype mismatch with param 1 – Ňɏssa Pøngjǣrdenlarp Oct 05 '14 at 15:50
  • `Adapter = New MySqlDataAdapter("Insert into tbluser(UserID,Name,UserType,Password) values('" & txtUserId.Text & "' ,'" & txtName.Text & "','" & cmbUserType.Text & "',AES_ENCRYPT('" & txtpass.Text & "','x'))", connection)` try this –  Oct 05 '14 at 15:51
  • Assign the SQL statement to a string, then print it out. Edit your question with the results. This is a problem of parameter substitution so look at what you are doing and the problem will probably be obvious. – Gordon Linoff Oct 05 '14 at 15:51
  • You need to use the `MySqlCommand` class instead. And as always: **[How do I create a parameterized SQL query? Why Should I?](http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i)** – Bjørn-Roger Kringsjå Oct 05 '14 at 15:55

1 Answers1

0
Adapter = New MySqlDataAdapter("Insert into tbluser (UserID
                                                ,Name
                                                ,UserType
                                                ,Password) 
                             values( '" & txtUserId.Text & "'
                                   , '" & txtName.Text & "'
                                   , '" & cmbUserType.Text & "'
                                   , '" & "'
                                   , AES_ENCRYPT('" & txtpass.Text & "','x'))", connection)

You have more values than you have defined columns to insert. It looks like the problem is an empty field between the UserType and the Password. Revise it like so should resolve the column count error:

Adapter = New MySqlDataAdapter("Insert into tbluser ( UserID
                                                    , Name
                                                    , UserType
                                                    , Password) 
                                      values( '" & txtUserId.Text & "' 
                                            , '" & txtName.Text & "' 
                                            , '" & cmbUserType.Text & "'
                                            , AES_ENCRYPT('" & txtpass.Text & "','x'))"
                               , connection)