0

I was trying to use the insert query on a small vb application. When I typed in the data and tried to upload it via a button, an error shows up: System.Data.OleDb.OleDbException: 'An INSERT INTO query cannot contain a multi-valued field.' I have tried checking the access database and i do not see any column that has been set to multivalue. Kindly assist

Private Sub AddClubMember(member As ClubMember)
        Using connection As New OleDbConnection(connectionString)
            connection.Open()

            Dim query As String = "INSERT INTO members (FullName, Gender, DateOfBirth, NextOfKin, ContactDetails, SubCounties, SchoolOrCollege, GamesOfInterest, Weight, Height, SpecialNeeds) VALUES (@FullName, @Gender, @DateOfBirth, @NextOfKin, @ContactDetails, @SubCounties, @SchoolOrCollege, @GamesOfInterest, @Weight, @Height, @SpecialNeeds)"

            Using command As New OleDbCommand(query, connection)
                command.Parameters.AddWithValue("@MemberID", member.MemberID)
                command.Parameters.AddWithValue("@FullName", member.FullName)
                command.Parameters.AddWithValue("@Gender", member.Gender)
                command.Parameters.AddWithValue("@DateOfBirth", member.DateOfBirth)
                command.Parameters.AddWithValue("@NextOfKin", member.NextOfKin)
                command.Parameters.AddWithValue("@ContactDetails", member.ContactDetails)
                command.Parameters.AddWithValue("@SubCounties", member.SubCounties)
                command.Parameters.AddWithValue("@SchoolOrCollege", member.SchoolOrCollege)
                command.Parameters.AddWithValue("@GamesOfInterest", member.GamesOfInterest)
                command.Parameters.AddWithValue("@Weight", member.Weight)
                command.Parameters.AddWithValue("@Height", member.Height)
                command.Parameters.AddWithValue("@SpecialNeeds", member.SpecialNeeds)


                command.ExecuteNonQuery()
            End Using
        End Using
    End Sub

Trying to add data to populate a table in a database.

  • Maybe https://stackoverflow.com/questions/45496983/an-insert-into-query-cannot-contain-a-multi-valued-field ? – Timothy G. Jun 02 '23 at 13:24
  • 3
    What is `@MemberID` doing as a parameter? Take it out? – Michael Foster Jun 02 '23 at 13:59
  • The following may be of interest: https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbparameter?view=dotnet-plat-ext-7.0#remarks – Tu deschizi eu inchid Jun 02 '23 at 14:09
  • Is one of your columns the Attachment data type? – jmcilhinney Jun 02 '23 at 14:46
  • @jmcilhinney I do not understand your question, kindly elaborate. – user22007770 Jun 02 '23 at 17:07
  • The issue is that [OleDb](https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb?view=windowsdesktop-7.0) doesn't use named parameters. See the URL in my previous comment for more information. Also, using _AddWithValue_ may (or may not) result in an incorrect error message. – Tu deschizi eu inchid Jun 02 '23 at 17:29
  • As suggested above, you should first fix the parameters by removing the inappropriate one and using `Add` instead of `AddWithValue` and specifying the data type explicitly. If you do that and still have an issue, tell us what the data type is for each column in the database. If one of them is `Attachment` then, as I alluded to, that is your issue. `Attachment` data can be retrieved using ADO.NET with a little jiggery-pokery but it cannot be saved. For that you would need to use (I think) DAO. – jmcilhinney Jun 03 '23 at 05:59

0 Answers0