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
  1. Home
  2. General Programming
  3. Visual Basic
  4. oledb error

oledb error

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasehelpquestion
2 Posts 2 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.
  • G Offline
    G Offline
    GaryKoh
    wrote on last edited by
    #1

    hello i have build a database using MS ACCESS and write a coding in VB.NET to connect it as below Imports System.Data.OleDb Public Class addItem Inherits System.Windows.Forms.Form Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0; datasource = Application.ExecutablePath + \LibrarySystem.mdb") Private Sub saveB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveB.Click myconnection.Open() Dim mycom As New OleDbCommand("INSERT INTO Product(product_code) VALUES ('" & productTb.Text & "')", myconnection) Dim MyReader As OleDbDataReader = mycom.ExecuteReader() mycom.ExecuteNonQuery() myconnection.Close() MyReader.Close() mycom.Dispose() End Sub but when i click on the saveB button, the error below show up An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll which point to myconnection.Open() may i know what i did wrong? thank you in advance Gary

    D 1 Reply Last reply
    0
    • G GaryKoh

      hello i have build a database using MS ACCESS and write a coding in VB.NET to connect it as below Imports System.Data.OleDb Public Class addItem Inherits System.Windows.Forms.Form Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0; datasource = Application.ExecutablePath + \LibrarySystem.mdb") Private Sub saveB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveB.Click myconnection.Open() Dim mycom As New OleDbCommand("INSERT INTO Product(product_code) VALUES ('" & productTb.Text & "')", myconnection) Dim MyReader As OleDbDataReader = mycom.ExecuteReader() mycom.ExecuteNonQuery() myconnection.Close() MyReader.Close() mycom.Dispose() End Sub but when i click on the saveB button, the error below show up An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll which point to myconnection.Open() may i know what i did wrong? thank you in advance Gary

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      GaryKoh wrote: Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0; datasource = Application.ExecutablePath + \LibrarySystem.mdb") This is your connection string. So it actually evaluates the variable you put in it, shouldn't it look more like this:

      Dim myconnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.ExecutablePath & "\LibrarySystem.mdb")

      Better yet, assemble the path name to the database using the proper function:

      Dim dbPath As String = Path.Combine(Application.ExecutablePath, "LibrarySystem.mdb")

      Then use this to open you database:

      Dim myconnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath)

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      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