INSERT INTO Problem

VB , INSERT INTO , ADO.NET Basildon, United Kingdom
  • 8 years ago

    Hi I wonder if anyone can help,

    I'm fairly new to ADO.NET and am trying to create a program that picks up a value from one table in access, displays it in a command prompt and then copies selected data to another table. My code i am having problems with is below. The Declared values are the ones I wish to write to a table and when I put in break points and step through the values are shown correctly, however when I get to the Execute query at the bottom I get the following error. Any Ideas? Thanks all help appreciated.

    "No value given for one or more required parameters".

            Dim myOleDbConnection As OleDb.OleDbConnection
            Dim insert As String
            Dim value1 = objDataRow.Item("ContactID")
            Dim value2 = objDataRow.Item("FirstName")
            Dim value3 = objDataRow.Item("LastName")
            Dim value4 = objDataRow.Item("Sent")
    
            Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source = C:\Users\Edward\Desktop\db1.mdb;"
    
            'insert = "INSERT INTO Cancelled (ContactID, FirstName, LastName, Sent) VALUES (" & value1 & " ," & value2 & " ," & value3 & " ," & value4 & ")"
    
            myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)
            myOleDbConnection.Open()
            Dim myOleDbCommand As New OleDb.OleDbCommand(insert, myOleDbConnection)
    
            myOleDbCommand = myOleDbConnection.CreateCommand
    
            myOleDbCommand.CommandType = CommandType.Text
    
            myOleDbCommand.CommandText = insert
    
            myOleDbCommand.ExecuteNonQuery()
    
            myOleDbConnection.Close()
    
  • 8 years ago

    Hi You have done the mistake while inserting values didn't use 'quotes in inserting coulmns values. I have given the soultion of your problem by correcting your code please check the soultion at http://aspnetans.blogspot.com/2009/06/no-value-given-for-one-or-more-required.html

  • 8 years ago

    Hi You have done the mistake while inserting values didn't use 'quotes in inserting coulmns values. I have given the soultion of your problem by correcting your code please check the soultion at (http://aspnetans.blogspot.com/2009/06/no-value-given-for-one-or-more-required.html)

  • 8 years ago

    Thanks so much for your help on this, it has really helped me with this.

    Thank you for your time and effort :-)

  • 8 years ago

    Hi EDM83,

    I think your vb code are Ok the only problem that you have is the single code that you have mentioned front of the sql string line. since you have already declared the string of insert method. please try to remove that code front of the insert string and it will work. If you would have coded in c# it would have indicate where you have the problem from cause C# is a case senstive. I am not sure about the VB.

    Hope this helps mate. regards, Ahmed Yassin

  • 8 years ago

    Thanks Ahmed, I have got it sorted now. Although I hope to move onto C# fairly soon so your help is apprecaited.

    Thanks mate

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill