4 Replies - 191 Views - Last Post: 22 July 2019 - 07:14 AM Rate Topic: -----

#1 xiwen_99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 19

Commend.ExecuteNonQuery() is error.

Posted 21 July 2019 - 07:53 PM

I was doing a question for creating online delivery services for sharwarma. When customer select the food and add it into the cart, data will be insert into the database "Foodorder" with values.

 Private Sub BtnFalafelSandCart_Click(sender As Object, e As EventArgs) Handles btnFalafelSandCart.Click
        Dim con As New OleDbConnection

        con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=Foodorder.mdb"

        Dim DBCommand As String = "Insert into [Foodorder]([Type],[Foodname],[Quantity],[Price])Values([Main Course],[Falafel Sandwich],[1],[6])"

        Using conn As New OleDb.OleDbConnection(con.ConnectionString)

            Using Command As OleDbCommand = New OleDbCommand(DBCommand, con)

                Command.CommandType = CommandType.Text
                Command.Parameters.AddWithValue("Colunm", "Main Course")
                Command.Parameters.AddWithValue("Colunm", "Falafel Sandwich")
                Command.Parameters.AddWithValue("Colunm", "1")
                Command.Parameters.AddWithValue("Colunm", "6")
                MessageBox.Show("Order Added")
                con.Open()
                Command.ExecuteNonQuery() //** This is the coding where it is error when I select "Add to Cart" button.//



            End Using
        End Using
    End Sub 


Is This A Good Question/Topic? 0
  • +

Replies To: Commend.ExecuteNonQuery() is error.

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15268
  • View blog
  • Posts: 61,206
  • Joined: 12-June 08

Re: Commend.ExecuteNonQuery() is error.

Posted 21 July 2019 - 08:05 PM

Please copy/paste the entire error message.

What is column 1 and column 6?
Was This Post Helpful? 0
  • +
  • -

#3 xiwen_99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 19

Re: Commend.ExecuteNonQuery() is error.

Posted 21 July 2019 - 08:14 PM

View Postmodi123_1, on 21 July 2019 - 08:05 PM, said:

Please copy/paste the entire error message.

What is column 1 and column 6?


System.Data.OleDb.OleDbException: 'Data type mismatch in criteria expression.'
>This is the message that show when running the VB.

Attachment has the full picture.

View Postmodi123_1, on 21 July 2019 - 08:05 PM, said:

Please copy/paste the entire error message.

What is column 1 and column 6?


Column, "1" and Column, "6".
1 and 6 is the value of the column. 1 is the quantity and price is 6.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,231
  • Joined: 12-December 12

Re: Commend.ExecuteNonQuery() is error.

Posted 22 July 2019 - 03:25 AM

Textual values need to be provided surrounded with single quotes, not square brackets.

You are not providing parameters, nor their values, correctly.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15268
  • View blog
  • Posts: 61,206
  • Joined: 12-June 08

Re: Commend.ExecuteNonQuery() is error.

Posted 22 July 2019 - 07:14 AM

Your INSERT would list three key things:
- table name
- column name
- parameter names in the order of the column names


INSERT INTO tableName (col1, col2, ...)
VALUES (@param1, @param2, ...)



Your parameters would be added.

cmd.Parameters.Add("@param1", SqlDbType.VarChar).Value = "1"
cmd.Parameters.Add("@param2", SqlDbType.VarChar).Value = "6"


.. or what ever your type and values are.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1