0

Hi everyone,
I'm creating a booking application for a hotel and have encountered an error on the following code;

Public Class Seaside_Hotel_DB
    Dim dbconn As OleDb.OleDbConnection
    Dim dbcmd As New OleDb.OleDbCommand
    Dim dbread As OleDb.OleDbDataReader
    Dim spath As String
    Public Sub New()
        spath = Application.StartupPath
        spath = spath.Replace("\bin\Debug", "")
        spath = spath + "\Seaside Hotel.mdb"
        dbconn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & spath & ";Persist Security Info=True")
    End Sub
    Public Function NewClient(ByVal cname As String, ByVal adr As String, ByVal city As String, ByVal pcode As Int32, ByVal phone As String) As Boolean
        Dim query As String
        Try
            dbconn.Open()
            query = "insert into Customer (CustName,Address,City,PostCode,Phone) values ('" & cname & "','" & adr & "','" & city & "'," & pcode & ",'" & phone & "')"
            dbcmd = New OleDb.OleDbCommand(query, dbconn)
            dbcmd.ExecuteNonQuery()
            dbconn.Close()
            Return True
        Catch ex As OleDb.OleDbException
            Return False
        End Try
    End Function

The error is the dbconn.open() in the public function New Client.

Your assistance will be appreciated.

Many thanks

Edited by YungSoprano: n/a

6
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by YungSoprano
Featured Replies
  • This error may relate to which excel edition you use or you can choose another provider instead "Microsoft.Jet.OLEDB.4.0" Read More

  • Try to put your database in the same location as your application and run it again. Read More

  • [CODE] OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & spath & ";Persist Security Info=True") [/CODE] Your connection string might be incorrect, it looks like it is missing some things. Here is a good reference for connection strings: [url]http://www.connectionstrings.com/excel[/url] Read More

1

This error may relate to which excel edition you use or you can choose another provider instead "Microsoft.Jet.OLEDB.4.0"

0

Your database path setup looks a bit odd.
do a

MsgBox(dbconn.DataSource)

just before the dbconn.open() command and see if the database is stored at the path that is shown in the messagebox.

1

Try to put your database in the same location as your application and run it again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.