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 1066923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:05:04+00:00 2026-05-16T20:05:04+00:00

Hey everyone. I’m fairly new to VB.NET and I’m looking to create a module

  • 0

Hey everyone. I’m fairly new to VB.NET and I’m looking to create a module that will contain all general SQL functionality like connect, disconnect and execute a sql query etc.

I think I’m almost there but the code keeps bombing in one place.

Can anyone see what is wrong with the following code?

It bombs here, setting the command object to a connection object. The opening and closing of the connection works fine.

cmdSystem.Connection = cnSystem

Or maybe I’m just thinking old VB and am going about this all wrong.

Public Module modGeneral

Private cnSystem As New SqlClient.SqlConnection
Private cmdSystem As SqlClient.SqlCommand

Public Sub ConnectToSQL()

    Dim sConnectionString As String = "Data Source=SQL;Initial Catalog=XXXX;User ID=XXXX;Password=XXXX"

    Try
        cnSystem.ConnectionString = sConnectionString
        cnSystem.Open()
    Catch ex As Exception

    End Try

End Sub
Public Sub DisconnectFromSQL()

    Try
        cnSystem.Close()
        cnSystem.Dispose()
    Catch ex As Exception

    End Try

End Sub
Public Function lExecuteSQL(ByVal sSQL As String) As Long

    Dim lRecordsAffected As Long = 0

    Try
        cmdSystem.Connection = cnSystem
        cmdSystem.CommandText = sSQL
        lRecordsAffected = cmdSystem.ExecuteNonQuery()
        cmdSystem.Dispose()
    Catch ex As Exception

    End Try

    Return lRecordsAffected

End Function

End Module

Thanks in advance.

  • 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-16T20:05:05+00:00Added an answer on May 16, 2026 at 8:05 pm

    at some point, you need to instantiate your command object like you did the connection.

    have you considered having these functions in a class instead of a module?

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

Sidebar

Related Questions

Hey everyone... I'm not too familiar with PHP... but I have PHP code that
Hey everyone, I am trying to ( temporarily! ) do some ASP.NET and C#
Hey everyone, I am working on parsing the PDF content stream to be able
Hey everyone, this is my first post up on StackOverflow! WOO! Anyhow, onto my
Hey everyone, I've been creating a little chat bot (for fun and practice). I
Hey everyone. While I'm trying to learn some PHP and mySQL, I ran into
Hey everyone, take a look at the code below and appreciate how messy the
Hey everyone. I have a fair amount of experience developing iOS apps, but nothing
Hey everyone, I was wondering if someone could point me in the right direction

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.