shingo99 Posted January 4, 2005 Posted January 4, 2005 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 and this error points to the code below myconnection.Open() may i know what i did wrong? i follow the instruction that was given by this thread http://www.xtremedotnettalk.com/showthread.php?t=69746 but i still getting the same error can please help? thank you in advance Quote
michael_hk Posted January 4, 2005 Posted January 4, 2005 Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0; datasource = Application.ExecutablePath + \LibrarySystem.mdb") You mix some code (Application.ExecutablePath) in your connection string. Quote There is no spoon. <<The Matrix>>
kejpa Posted January 4, 2005 Posted January 4, 2005 Hi, First of all, which line is the one producing the exception? That's where you should start searching for something wrong. Secondly, Dim MyReader As OleDbDataReader You're executing a query which don't yield any resulting rows, I wouldn't have used a DataReader to insert records. I'd use a OleDbCommand object... HTH /Kejpa Quote
shingo99 Posted January 4, 2005 Author Posted January 4, 2005 hi michael n kejpa 1st of all the code that produce this error An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll is from this line of coding myconnection.Open() 2nd even without the Dim MyReader As OleDbDataReader i still get the same error 3rd even if i didnt set it to (Application.ExecutablePath) it still give me that error i really dont know where when wrong since in the tutorial is stated clear that this code will work Quote
Administrators PlausiblyDamp Posted January 4, 2005 Administrators Posted January 4, 2005 try Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0; datasource = " & Application.ExecutablePath & " \LibrarySystem.mdb") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
shingo99 Posted January 4, 2005 Author Posted January 4, 2005 thx...but still get the same error. is the problem of the error arise from my database? i create it seperately and just paste it to the bin my friend say that i need to create the Access databse using vb in order for the codind to work is this true? sorry to trouble u all Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.