Skip to main content

Vb.Net and MS-Access database Conection | TechbyMati


    Vb.Net and MS-Access database Conection

    Open connection to password protected Access database:
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"
    connStr = "Provider=Microsoft.Jet.OLEDB.4.0; " + 
               "Data Source=G:\\Backup\\Kashif\\xyzDB.mdb"; 
               qryStr = "select content,websiteID  from content"; 
               dbConn = new OleDbConnection(connStr);
    Examples: 
        SQL:  "server=tonydev;database=northwind;uid=tony;pwd=hrmmm" 
                 "server=tonydev;database=northwind;trusted_connection=yes" 
        OLE: "Provider=Microsoft.Jet.OLEDB.4.0; Data source=C:\tony.mdb"
        Public Function FetchData(ByVal FileName As String) As DataSet
            'Define the connectors
            Dim oConn As OleDbConnection
            Dim oComm As OleDbCommand
            Dim oData As OleDbDataAdapter
            Dim resultSet As New DataSet
            Dim oConnect, oQuery As String
            'Define connection string
            oConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";User ID=Admin;Password="
            'Query String
            oQuery = "SELECT * FROM accessTest"
            'Instantiate the connectors
            oConn = New OleDbConnection(oConnect)
            oComm = New OleDbCommand(oQuery, oConn)
            oData = New OleDbDataAdapter(oQuery, oConn)
            Try
                'Open connection
                oConn.Open()
                'Fill dataset
                oData.Fill(resultSet, "accessTest")
                'Close connection
                oConn.Close()
            Catch ex As OleDb.OleDbException
            Catch ex As Exception
                'Show error message and exit
                MsgBox(ex.Message & vbCrLf & ex.StackTrace)
            Finally
                'Dispose the connector objects
                If Not (oConn Is Nothing) Then oConn.Dispose()
                oConn = Nothing
                If Not (oComm Is Nothing) Then oComm.Dispose()
                oComm = Nothing
                If Not (oData Is Nothing) Then oData.Dispose()
                oData = Nothing
            End Try
            'Return results
            Return resultSet
        End Function
    OLE DB, OleDbConnection (.NET) 
    Standard security:
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;" 
    Workgroup (system database):
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;" 
    With password:
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;" 


    cnHotel = New OleDbConnection
            Try
                With cnHotel
                    If .State = ConnectionState.Open Then .Close()
                    .ConnectionString = cnString
                    .Open()
                End With
            Catch ex As OleDbException
                MsgBox(ex.ToString)
            End Try

     

    Comments

    Popular posts from this blog

    Marg ERP 9+ Shortcut Keys

    Contents Marg ERP 9+ Shortcut Keys           F2        - Sale Bill      Alt+A     - Counter Sale      Alt+P     - Purc.Challan      Alt+S     - Sale Challan      Alt+Ins   - Cash Challan      Ctrl+T/Z  - Copy Bill      Ctrl+F3/F3- Sale Modify      Ctrl+O    - Import/Export      Ctrl+K    - Stock Less      Ctrl+D    - Stock Add      Ctrl+R    - Cash/Cr/Setup      Ctrl+P    - Load PO/PenChall      Ctrl+F9   - Bill-Adjustments      Ctrl+V    - QRID Or...

    Marg ERP 9+ Software Download: The Ultimate Guide to GST Billing & Accounting for SMEs (2026)

    Marg ERP 9+ Software Download: The Ultimate Guide to GST Billing & Accounting for SMEs If you run a small or medium-sized enterprise (SME), you already know that managing daily operations can feel like a high-wire balancing act. Between tracking inventory, ensuring accurate billing, managing customer relationships, and staying compliant with ever-changing GST regulations, there is very little room for error. Manual accounting and outdated spreadsheet methods no longer cut it in today’s fast-paced digital economy. Enter Marg ERP 9+ , one of India's most trusted and widely used business management platforms. Whether you are a retail shop owner, a massive FMCG distributor, or a pharmacy handling thousands of complex SKUs, finding the right software is critical to scaling your business. In this comprehensive, SEO-friendly guide, we will dive deep into what Marg Software is, explore its inspiring history, break down its top-tier features, and show you exactly...