Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. A class for DataBase Connection Codes

A class for DataBase Connection Codes

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasecsharphelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shahab2025
    wrote on last edited by
    #1

    Dear Sir I have many forms in my vb.net projects I have to write(copy) all connection codes to connect DB for each form Is any better way???? for example a class or a dll to help me ???? Generally I want another method (class or dll file) to call for loading of my forms... Sorry about my bad english... Thanks

    D T 3 Replies Last reply
    0
    • S shahab2025

      Dear Sir I have many forms in my vb.net projects I have to write(copy) all connection codes to connect DB for each form Is any better way???? for example a class or a dll to help me ???? Generally I want another method (class or dll file) to call for loading of my forms... Sorry about my bad english... Thanks

      D Offline
      D Offline
      darkyro
      wrote on last edited by
      #2

      yu can create a class with this code: Public con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & My.Settings.dbBase.ToString & ";Jet OLEDB:Database Password=" & My.Settings.dbBasePass.ToString & ";") where i use a settings option to store the informations converted to string : data base : My.Settings.dbBase.ToString password : My.Settings.dbBasePass.ToString i hope help you ^^ my english is not good too ^^" ;)

      1 Reply Last reply
      0
      • S shahab2025

        Dear Sir I have many forms in my vb.net projects I have to write(copy) all connection codes to connect DB for each form Is any better way???? for example a class or a dll to help me ???? Generally I want another method (class or dll file) to call for loading of my forms... Sorry about my bad english... Thanks

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        Standard object orientated multitier design patterns help here. Been around for years. You need to abstract all your dataAccess code (creating the connection, calling SQL etc.) into a separate DataAccess class. Then from any form in the application just call your dataaccess class. MSDN tutorial 1: Creating a Data Access Layer[^] should give you a good start point.

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

        1 Reply Last reply
        0
        • S shahab2025

          Dear Sir I have many forms in my vb.net projects I have to write(copy) all connection codes to connect DB for each form Is any better way???? for example a class or a dll to help me ???? Generally I want another method (class or dll file) to call for loading of my forms... Sorry about my bad english... Thanks

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #4

          I should add that althought the MSDN articl I posted about is for ASP.Net Web Applications the DataAccess logic and code is identical for Windows Forms applications.

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups