Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:42:17+00:00 2026-06-10T18:42:17+00:00

Good day everyone. I would like to ask for help regarding my code to

  • 0

Good day everyone. I would like to ask for help regarding my code to update specific record in the database. My back-end is Microsoft Access and front-end is Visual Basic. It gives me an error “No value given for one or more required parameters”. Also, I receive a problem about “object reference not set to an instance of an object.”

Here’s my code. Thank you 🙂

    Private Sub UpdateClient()

    Dim sqlUpdateClient As String = "UPDATE tblClient SET clientCompany = @clientCompany, clientStreetAddress = @clientStreetAddress, clientCity = @clientCity, clientContactPerson = @clientContactPerson, clientContactNumber = @clientContactNumber, clientEmail = @clientEmail, clientMobileNumber = @clientMobileNumber WHERE clientID = " + selectedClient
    Dim recordsAffected As Integer = 0
    Dim accessCommand As New OleDbCommand(sqlUpdateClient, accessConnection)
    accessCommand.CommandText = sqlUpdateClient

    accessCommand.Parameters.AddWithValue("@clientCompany", txtClientCompany.Text)
    accessCommand.Parameters.AddWithValue("@clientStreetAddress", txtClientStreetAddress.Text)
    accessCommand.Parameters.AddWithValue("@clientCity", txtClientCity.Text)
    accessCommand.Parameters.AddWithValue("@clientContactPerson", txtClientContactPerson.Text)
    accessCommand.Parameters.AddWithValue("@clientContactNumber", txtClientPhoneNumber.Text)
    accessCommand.Parameters.AddWithValue("@clientEmail", txtClientEmailAddress.Text)
    accessCommand.Parameters.AddWithValue("@clientMobileNumber", txtClientMobileNumber.Text)

    Try

        accessConnection.Open()
        recordsAffected = accessCommand.ExecuteNonQuery

    Catch ex As Exception

        lblError.Text = ex.ToString

    Finally

        accessConnection.Close()

    End Try

    If recordsAffected = 0 Then
        MsgBox("Record updated failed!", MsgBoxStyle.Exclamation, "Project Analysis System")
    Else
        MsgBox("Record updated successfully!", MsgBoxStyle.Information, "Project Analysis System")
        PopulateClientList()
    End If

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:42:18+00:00Added an answer on June 10, 2026 at 6:42 pm

    Is accessConnection a global (connection object) variable? You must have created another instance of that object on that procedure.

    One more thing, clientID is also be parameterized. then add this line

    accessCommand.Parameters.AddWithValue("@clientID", selectedClient)
    

    UPDATE 1

    Private Sub UpdateClient()
    
        Dim recordsAffected As Integer = 0
        Dim sqlUpdateClient As String = "UPDATE tblClient " & _
                                        "SET clientCompany = ?, " & _
                                        "   clientStreetAddress = ?, " & _
                                        "   clientCity = ?, " & _
                                        "   clientContactPerson = ?, " & _
                                        "   clientContactNumber = ?, " & _
                                        "   clientEmail = ?, " & _
                                        "   clientMobileNumber = ? " & _
                                        "WHERE clientID = ?"
    
        Using accessConnection As New OleDbConnection("connectionStringHere")
            Using accessCommand As New OleDbCommand()
                With accessCommand
                    .Connection = accessConnection
                    .CommandType = CommandType.Text
                    .CommandText = sqlUpdateClient
                    .Parameters.AddWithValue("clientCompany", txtClientCompany.Text)
                    .Parameters.AddWithValue("clientStreetAddress", txtClientStreetAddress.Text)
                    .Parameters.AddWithValue("clientCity", txtClientCity.Text)
                    .Parameters.AddWithValue("clientContactPerson", txtClientContactPerson.Text)
                    .Parameters.AddWithValue("clientContactNumber", txtClientPhoneNumber.Text)
                    .Parameters.AddWithValue("clientEmail", txtClientEmailAddress.Text)
                    .Parameters.AddWithValue("clientMobileNumber", txtClientMobileNumber.Text)
                    .Parameters.AddWithValue("clientID", selectedClient)
                End With
                Try
                    accessConnection.Open()
                    recordsAffected = accessCommand.ExecuteNonQuery()
                Catch ex As OleDBException
                    lblError.Text = ex.Message.ToString()
                Finally
                    accessConnection.Close()
                End Try
    
                If recordsAffected = 0 Then
                    MsgBox("Record updated failed!", MsgBoxStyle.Exclamation, "Project Analysis System")
                Else
                    MsgBox("Record updated successfully!", MsgBoxStyle.Information, "Project Analysis System")
                    PopulateClientList()
                End If
            End Using
        End Using
    
    End Sub
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day everyone, i have faced with such an issue as linkage error like
Good Day Everyone I was hoping if you could help me understand the concepts
Good day everyone. I have a question regarding drawing libraries for C#. I always
Good day, everyone. Could somebody explain why following code does work in Google Chrome
Good day everyone, this is one of those areas that is a little over
Good day everyone. I have a question about making and using derived classes of
Good day everyone! I am trying to understand how buffer overflow works. Right now,
Good day everyone. I have an audio class, that plays a .wav file. But
Good day everyone I need to execute command on linux machine this command is
Good Day Everyone, My website uses a datafeed to upload product listings on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.