none
ExecuteNonQuery is not declared

    Question

  • The following code gives an error that there is a syntax error in the INSERT INTO Command and upon further investigation it appears that the ExecuteNonQuery is not declared.  I have tried several different iterations to no avail.  Maybe a fresh set of eyes can pinpoint my grievous error.

       

    PrivateSubcmdSave_Click(sender AsObject, e AsEventArgs) HandlescmdSave.Click

           

    DimdbInsCmd AsNewOleDbCommand


           

    DimdbInsCmdString AsString


            dbInsCmdString =

    "INSERT INTO tblProblems(ProblemDesc, Section, Component, ComponentNumber, Employee, Resolution)VALUES(@ProblemDesc,

                @ProblemDate, @Section, @Component, @ComponentNumber, @Employee, @Resolution"


            dbConn.Open()

           

    WithdbInsCmd

                .CommandType =

    CommandType.Text

                .CommandText = dbInsCmdString

                .Parameters.AddWithValue(

    "@ProblemDesc", txtProblem.Text)

                .Parameters.AddWithValue(

    "@ProblemDate", dtPicker.ToString)

                .Parameters.AddWithValue(

    "@Section", cboSection.SelectedItem)

                .Parameters.AddWithValue(

    "@Component", cboComponent.SelectedItem)

                .Parameters.AddWithValue(

    "@ComponentNumber", cboComponentNumber.SelectedItem)

                .Parameters.AddWithValue(

    "@Employee", cboEmployee.SelectedItem)

                .Parameters.AddWithValue(

    "@Resolution", txtResolution.Text)

                .Connection = dbConn

                MsgBox(dbInsCmdString)

                .ExecuteNonQuery()

           

    EndWith


           

    'dbInsCmd.ExecuteNonQuery()


            dbConn.Close()

           

    Me.Close()

       

    EndSub

    Wednesday, August 10, 2016 1:19 PM

Answers

  • The issue is not in 'With' Statement and using .ExecuteNonQuery()

    Are you able to debug the SelectedItem of your comboboxes?

    Make sure that the values in the combo boxes have the same type as they should be added to your table in the database.


    Thanks, Mahmoud

    Wednesday, August 10, 2016 3:43 PM

All replies

  • Hi,

    you need to call the ExecuteNonQuery method of the the command object like that

    DimdbInsCmd.ExecuteNonQuery()


    Thanks, Mahmoud

    Wednesday, August 10, 2016 1:43 PM
  • The dbInsCmd is already declared in the block.  How else would I be able to do the With statement?
    Wednesday, August 10, 2016 1:59 PM
  • The issue is not in 'With' Statement and using .ExecuteNonQuery()

    Are you able to debug the SelectedItem of your comboboxes?

    Make sure that the values in the combo boxes have the same type as they should be added to your table in the database.


    Thanks, Mahmoud

    Wednesday, August 10, 2016 3:43 PM
  • Could you post your code with the "Insert Code Block" function of the forum so that it is readable.

    Or if you cannot do that: Copy it to a notepad editor first and then copy & paste from there.

    Your code is simply not readable at all. 

    It is possible to call the ExecuteNonQuery() method inside a With block of the OleDbCommand instance with a simply .ExecuteNonQuery().

    With kind regards,

    Konrad

    Wednesday, August 10, 2016 3:44 PM
    Moderator