Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. gettinig insert error and need help

gettinig insert error and need help

Scheduled Pinned Locked Moved Visual Basic
helpdatabasemysql
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MeterMan
    wrote on last edited by
    #1

    Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCommit.Click Dim ra As Integer Dim MyConn As New System.Data.OleDb.OleDbConnection(Connstring) MyConn.Open() ' open connection Dim MySql As String = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values " & tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString Dim command As New System.Data.OleDb.OleDbCommand(MySql, MyConn) ra = command.ExecuteNonQuery() MyConn.Dispose() Response.Write("New Row inserted" & ra) End Sub End Class Can someone tell me why I'm getting a insertion syntax error when trying to run this code. My db has those exact fields. This is an access db by the way if that matters. thanks for the help Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

    P D 2 Replies Last reply
    0
    • M MeterMan

      Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCommit.Click Dim ra As Integer Dim MyConn As New System.Data.OleDb.OleDbConnection(Connstring) MyConn.Open() ' open connection Dim MySql As String = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values " & tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString Dim command As New System.Data.OleDb.OleDbCommand(MySql, MyConn) ra = command.ExecuteNonQuery() MyConn.Dispose() Response.Write("New Row inserted" & ra) End Sub End Class Can someone tell me why I'm getting a insertion syntax error when trying to run this code. My db has those exact fields. This is an access db by the way if that matters. thanks for the help Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

      P Offline
      P Offline
      Paradise Bride
      wrote on last edited by
      #2

      try this.... in ur code page in the top of the page wrie Imports System.Data.oledb like this... Imports System.Data.oledb Public Class Form1 Inherits System.Windows.Forms.Form and in ur button Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCommit.Click Dim MySql As as new oledbcommand mysql.Connection = OleDbConnection1 oledbconnection1.Open() ' open connection my sql.commandtext = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values( " tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString) mysql.ExecuteNonQuery() oledbconnection1.close() End Sub End Class that if u create ur connectin by the wizard and as i know the wizard allready will give u name of ur connection as (oledbconnection1) i hope that will work:) rusashksa@yahoo.com Sally<<<>>>tAkE mE 2 uR pAraDiSe<<<>>>Sally

      M 1 Reply Last reply
      0
      • P Paradise Bride

        try this.... in ur code page in the top of the page wrie Imports System.Data.oledb like this... Imports System.Data.oledb Public Class Form1 Inherits System.Windows.Forms.Form and in ur button Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCommit.Click Dim MySql As as new oledbcommand mysql.Connection = OleDbConnection1 oledbconnection1.Open() ' open connection my sql.commandtext = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values( " tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString) mysql.ExecuteNonQuery() oledbconnection1.close() End Sub End Class that if u create ur connectin by the wizard and as i know the wizard allready will give u name of ur connection as (oledbconnection1) i hope that will work:) rusashksa@yahoo.com Sally<<<>>>tAkE mE 2 uR pAraDiSe<<<>>>Sally

        M Offline
        M Offline
        MeterMan
        wrote on last edited by
        #3

        No offense but I see no difference in the code you posted than that of mine. ONly things is your making it a shortcut by using Imports System.Data.oledb and your making a Oledbconnection which is what I'm doing in my code the connection string is write all that works the issue is the insert string. I use this same syntax with other dataaccess the only problem is the insert string its formated wrong and i'm not sure what i'm doing wrong. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

        1 Reply Last reply
        0
        • M MeterMan

          Protected Sub btnCommit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCommit.Click Dim ra As Integer Dim MyConn As New System.Data.OleDb.OleDbConnection(Connstring) MyConn.Open() ' open connection Dim MySql As String = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values " & tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString Dim command As New System.Data.OleDb.OleDbCommand(MySql, MyConn) ra = command.ExecuteNonQuery() MyConn.Dispose() Response.Write("New Row inserted" & ra) End Sub End Class Can someone tell me why I'm getting a insertion syntax error when trying to run this code. My db has those exact fields. This is an access db by the way if that matters. thanks for the help Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          MeterMan wrote:

          Dim MySql As String = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values " & tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString

          I've seen this WAY too many times... Junk like this just leads to problems that are difficult to find and opens you up to Injection attacks. You can avoid this by using Parameterized Queries instead. Search the articles for "Sql Injection Attacks" and you'll find a great article by Colin Angus Mackay, which will detail how to do this. Anyway, you're missing some quote marks, concantenation characters (&), parenthesisin the SQL statements, ..., and it just bugs the #&@% out of me to see people calling .ToString() on a Text property. Text returns a String, so why call .ToString() on a String?!?!?

          Dim MySql As String = "Insert into ExpenseReport " & _
          "(DateRow1, WhomRow1, CCardAmountRow1, PCardAmountRow1, " & _
          "CashAmount, VehicleNumRow1, ProjectnameRow1, TypeofExpenseRow1)" & _
          " values (" & tbxDate.Text & "," & tbxWhom.Text & "," & _
          tbxCCard.Text & "," & tbxPCard.Text & "," & tbxCash.Text & "," & _
          tbxVehicle.Text & "," & tbxProject.Text & "," & _
          ddnExpense.SelectedValue.ToString() & ")"

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            MeterMan wrote:

            Dim MySql As String = "Insert into ExpenseReport _ (DateRow1,WhomRow1,CCardAmountRow1,PCardAmountRow1,CashAmount,VehicleNumRow1,ProjectnameRow1, _ TypeofExpenseRow1) values " & tbxDate.Text.ToString & "," & tbxWhom.Text.ToString & "," & _ tbxCCard.Text.ToString & "," & tbxPCard.Text & "," & tbxCash.Text & "," & tbxVehicle.Text & "," & _ tbxProject.Text.ToString & "," & ddnExpense.SelectedValue.ToString

            I've seen this WAY too many times... Junk like this just leads to problems that are difficult to find and opens you up to Injection attacks. You can avoid this by using Parameterized Queries instead. Search the articles for "Sql Injection Attacks" and you'll find a great article by Colin Angus Mackay, which will detail how to do this. Anyway, you're missing some quote marks, concantenation characters (&), parenthesisin the SQL statements, ..., and it just bugs the #&@% out of me to see people calling .ToString() on a Text property. Text returns a String, so why call .ToString() on a String?!?!?

            Dim MySql As String = "Insert into ExpenseReport " & _
            "(DateRow1, WhomRow1, CCardAmountRow1, PCardAmountRow1, " & _
            "CashAmount, VehicleNumRow1, ProjectnameRow1, TypeofExpenseRow1)" & _
            " values (" & tbxDate.Text & "," & tbxWhom.Text & "," & _
            tbxCCard.Text & "," & tbxPCard.Text & "," & tbxCash.Text & "," & _
            tbxVehicle.Text & "," & tbxProject.Text & "," & _
            ddnExpense.SelectedValue.ToString() & ")"

            RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            M Offline
            M Offline
            MeterMan
            wrote on last edited by
            #5

            Thanks for the reply and also the word of warning on injects I will read that. One question. How do you make the page accept the changed values n a dropdownbox only when you hit commit button. Basically ddnExpense.SelectValue is changed and the other values are put into the text boxes but the pages has no idea what the value of ddnExpense is because it hasn't postedback. The thing is I don't want it to post back when i make a change in the dropdown because then Id loose all the data in my other fields. Any help on this would be great. Win32newb "Programming is like Sex, make a mistake and you end up providing support for a long time"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups