4 Replies - 582 Views - Last Post: 09 August 2012 - 11:43 AM Rate Topic: -----

#1 Dexterwess  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-December 11

syntax error in insert into statement

Posted 09 August 2012 - 10:47 AM

Hello , i have this code in my project that i would want it to insert into my database , but when that stage comes , it tells me syntax error in insert into statement:

   
Dim objCon As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OleDb.4.0; Data Source=D:\newProj\Pipes.mdb;")
        Dim objcommand As New OleDb.OleDbCommand


        'defining the parameters
        objcommand.Connection = objCon
        objcommand.CommandType = CommandType.Text
        objcommand.CommandText = "INSERT INTO tblPressurePipe" & _
        "(Type,Size,Quantity,Unit_Cost,Total_Cost,Transaction_Date,Available)" & _
        "VALUES(@type,@size,@quantity,@Cost,@Total,@TDate,@remain)"

        'defining the inputs



        With objcommand
            .Parameters.AddWithValue("@type", cboType.Text)
            .Parameters.AddWithValue("@size", cboSize.Text)
            .Parameters.AddWithValue("@quantity", txtQuantity.Text)
            .Parameters.AddWithValue("@Cost", txtCost.Text)
            .Parameters.AddWithValue("Total", txtTotalCost.Text)
            .Parameters.AddWithValue("@TDate", Form3.TDate.Text)
            .Parameters.AddWithValue("@remain", txtAvailable.Text)

        End With

        objCon.Open()

        objcommand.ExecuteNonQuery()

        objCon.Close()






This post has been edited by smohd: 09 August 2012 - 10:51 AM
Reason for edit:: Code tags fixed


Is This A Good Question/Topic? 0
  • +

Replies To: syntax error in insert into statement

#2 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: syntax error in insert into statement

Posted 09 August 2012 - 10:51 AM

your last code tag should be [/code] sir :)
Was This Post Helpful? 0
  • +
  • -

#3 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: syntax error in insert into statement

Posted 09 August 2012 - 11:27 AM

I did some searching and found this.

Maybe this will shed some light on the problem with your insert command.
Good luck! Please post the answer if you get it working, thanks!

View PostDexterwess, on 09 August 2012 - 10:47 AM, said:

   

        objcommand.CommandText = "INSERT INTO tblPressurePipe" & _
        "(Type,Size,Quantity,Unit_Cost,Total_Cost,Transaction_Date,Available)" & _
        "VALUES(@type,@size,@quantity,@Cost,@Total,@TDate,@remain)"


Was This Post Helpful? 0
  • +
  • -

#4 Dexterwess  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-December 11

Re: syntax error in insert into statement

Posted 09 August 2012 - 11:37 AM

View PostDexterwess, on 09 August 2012 - 10:47 AM, said:

Hello , i have this code in my project that i would want it to insert into my database , but when that stage comes , it tells me syntax error in insert into statement:

Thanks Dude, but you code ain't working , this one works:


'defining the parameters
        objcommand.Connection = objCon
        objcommand.CommandType = CommandType.Text
        objcommand.CommandText = "INSERT INTO tblPressurePipe" & _
        "([Type],[Size],[Quantity],Unit_Cost,Total_Cost,Transaction_Date,[Available])" & _
        "VALUES(@type,@size,@quantity,@Cost,@Total,@TDate,@remain)"





   
Dim objCon As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OleDb.4.0; Data Source=D:\newProj\Pipes.mdb;")
        Dim objcommand As New OleDb.OleDbCommand


        'defining the parameters
        objcommand.Connection = objCon
        objcommand.CommandType = CommandType.Text
        objcommand.CommandText = "INSERT INTO tblPressurePipe" & _
        "(Type,Size,Quantity,Unit_Cost,Total_Cost,Transaction_Date,Available)" & _
        "VALUES(@type,@size,@quantity,@Cost,@Total,@TDate,@remain)"

        'defining the inputs



        With objcommand
            .Parameters.AddWithValue("@type", cboType.Text)
            .Parameters.AddWithValue("@size", cboSize.Text)
            .Parameters.AddWithValue("@quantity", txtQuantity.Text)
            .Parameters.AddWithValue("@Cost", txtCost.Text)
            .Parameters.AddWithValue("Total", txtTotalCost.Text)
            .Parameters.AddWithValue("@TDate", Form3.TDate.Text)
            .Parameters.AddWithValue("@remain", txtAvailable.Text)

        End With

        objCon.Open()

        objcommand.ExecuteNonQuery()

        objCon.Close()






Was This Post Helpful? 0
  • +
  • -

#5 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: syntax error in insert into statement

Posted 09 August 2012 - 11:43 AM

Thanks for posting your solution!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1