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

  • SEARCH
  • Home
  • 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 6653133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:13:51+00:00 2026-05-26T01:13:51+00:00

Here is my sub for updating a Database using ODBC: Public Sub UpdateDatabase(ByVal sql

  • 0

Here is my sub for updating a Database using ODBC:

Public Sub UpdateDatabase(ByVal sql As String, ByVal parameters() As OdbcParameter)
    Dim connectionString As String = "dsn=" & ODBC & ";uid=" & UID & ";pwd="

    Try
        Using conn As OdbcConnection = New OdbcConnection(connectionString)
            Dim adapter As New OdbcDataAdapter(sql, conn)

            For Each parameter As OdbcParameter In parameters
                adapter.InsertCommand.Parameters.Add(parameter)
            Next

            conn.Open()

            adapter.InsertCommand.ExecuteNonQuery()
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

Here is an example calling it with empty parameters:

            Dim query As String = "INSERT INTO F_ARTICLE (AR_Ref) VALUES ('test')"
            Dim parameters As OdbcParameter() =
            {
            }
            UpdateDatabase(query, parameters)

But the following exception is shown:

NullReferenceException: Object reference not set to an instance of an object

Which seems to be triggered by this:

adapter.InsertCommand.ExecuteNonQuery()

Any idea what am I doing wrong here?

  • 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-05-26T01:13:52+00:00Added an answer on May 26, 2026 at 1:13 am

    I still don’t know why the previous sub didn’t work, but this is how I solved it:

    Public Sub UpdateDatabase(ByVal query As String, ByVal parameters() As OdbcParameter)
        Dim connectionString As String = "dsn=" & ODBC & ";uid=" & UID & ";pwd="
    
        Try
            Using conn As OdbcConnection = New OdbcConnection(connectionString)
                Using command As New OdbcCommand(query, conn)
    
                    For Each parameter As OdbcParameter In parameters
                        command.Parameters.Add(parameter)
                    Next
    
                    conn.Open()
    
                    command.ExecuteNonQuery()
                End Using
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code here Sub FooSub Dim db As New FooDataContext Dim u
Here's a short test program: sub foo($;@) { my $sql = shift; my @params
Here's my Application_OnError event sink in global.asax.vb: Sub Application_OnError(ByVal sender As Object, ByVal e
Here is the code for the button click event; Protected Sub CompetenciesButton_Click(ByVal sender As
Private Sub btnWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWord.Click Dim Inputter
Here's a snippit of perl code: sub insert_timesheet { my $dbh = shift; my
Here at work we have a very large application with multiple sub applications. (500
So here's the scenario, I'm building a theme that would display sub category of
I'm using Access 2007 to build a normalized database to replace one that uses
hey , I have a problem with updating a record using a domain service,

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.