I need some help bigtime. Psycocoder has helped me quite a bit, but I am running in the same problems over and over.
The basics...
Its a hotel reservation program..
I have a database.mdf which it consists of three tables: CustomersTBL , ReservationsTBL & RoomTBL
(it actually has more, but I am not using them yet)
For headache sake, In the customers table I obviously have IDENTIFIERS/PRIMARY keys as INT (CustomerID, ReservationID and RoomNumber) eveything is a TEXT field with the exception of in each of the tables.
On one form, I just use binding and add a row to the table and the only time I do a sql query is on the second firm when I want to look up the last person entered is sorted into the Reservations table.
(hehe.. forgot to add the file)
Public Class frm2CustomerEntry
Private Sub frm2CustomerEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Me.CUSTOMERTBLTableAdapter.Fill(Me.HOTELDATABASE_DATASET.CUSTOMERTBL)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newCustomerRow As HOTELDATABASE_DATASET.CUSTOMERTBLRow
newCustomerRow = HOTELDATABASE_DATASET.CUSTOMERTBL.NewCUSTOMERTBLRow
'--- Throws data into the customer database ---------------------------------------------------------------------
Try
Me.CUSTOMERTBLTableAdapter.Insert(Me.txtFname.Text, Me.txtLname.Text, Me.txtAddress1.Text, _
Me.txtAddress2.Text, Me.txtCity.Text, Me.cboSelectState.Text, Me.txtPhone.Text, _
CStr(Today), Me.txtEmail.Text, Me.txtZipcode.Text)
Me.CUSTOMERTBLTableAdapter.Fill(HOTELDATABASE_DATASET.CUSTOMERTBL)
frm3Reservations.txtFname.Text = Me.txtFname.Text
frm3Reservations.txtLname.Text = Me.txtLname.Text
frm3Reservations.txtAddress1.Text = Me.txtAddress1.Text
frm3Reservations.txtAddress2.Text = Me.txtAddress2.Text
frm3Reservations.txtCity.Text = Me.txtCity.Text
frm3Reservations.txtSelectState.Text = Me.cboSelectState.Text
frm3Reservations.txtZipcode.Text = Me.txtZipcode.Text
frm3Reservations.txtPhone.Text = Me.txtPhone.Text
frm3Reservations.txtEmail.Text = Me.txtEmail.Text
MessageBox.Show("Guest has been added to the Database")
Catch ex As System.Exception
MessageBox.Show(ex.Message, "Data input error")
End Try
Me.CUSTOMERTBLTableAdapter.Dispose()
Me.CUSTOMERTBLTableAdapter.Dispose()
frm3Reservations.Show()
Me.Close()
End Sub
Private Sub txtPhone_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtPhone.Validating
' validate zip is numeric
If Not IsPositive(txtPhone.Text) Then
' Display error message
MessageBox.Show("Phone must be a numerical number", "ERROR Invalid Phone Number")
txtPhone.SelectAll()
txtPhone.Focus()
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
Private Sub txtZip_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtZipcode.Validating
' validate zip is numeric
If Not IsPositive(txtZipcode.Text) Then
' Display error message
MessageBox.Show("Zipcode must be 5 digit numerical number", "ERROR Invalid ZipCode")
txtZipcode.SelectAll()
txtZipcode.Focus()
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
End Class
In the Reservations table:
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data
Public Class frm3Reservations
Private Sub ROOMTABLEBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ROOMTABLEBindingNavigatorSaveItem.Click
Me.Validate()
Me.ROOMTABLEBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.HOTELDATABASE_DATASET)
End Sub
Private Sub frm3Reservations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dtmSystemDate = Today
'TODO: This line of code loads data into the 'HOTELDATABASE_DATASET.RESERVATIONTBL' table. You can move, or remove it, as needed.
Me.RESERVATIONTBLTableAdapter.Fill(Me.HOTELDATABASE_DATASET.RESERVATIONTBL)
'TODO: This line of code loads data into the 'HOTELDATABASE_DATASET.ROOMTABLE' table. You can move, or remove it, as needed.
Me.ROOMTABLETableAdapter.Fill(Me.HOTELDATABASE_DATASET.ROOMTABLE)
DateTimeCheckIn.Value = Today
DateTimeCheckOut.Value = Today.AddDays(1)
DateTimeCheckIn.MinDate = Today 'On page load, sets the Minimum date to select to Today
DateTimeCheckIn.MaxDate = Today.AddDays(552) 'Sets the max calendar to 1.5 years into the future
DateTimeCheckOut.MinDate = Today.AddDays(1) 'On page load, sets the Minimum date to select to Today + 1
DateTimeCheckOut.MaxDate = Today.AddDays(552) 'Sets the max calendar to 1.5 years into the future
DateIN = DateTimeCheckIn.Value
End Sub
Private Sub FillToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillToolStripButton.Click
Try
Me.ROOMTABLETableAdapter.Fill(Me.HOTELDATABASE_DATASET.ROOMTABLE)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub CustomersTableViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomersTableViewToolStripMenuItem.Click
frm9CustomersTableView.Show()
End Sub
Private Sub btnSubmitReservation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmitReservation.Click
'+++++++++++++++++++++++++++++++ This process will connect to the database
Dim Rs1 As OleDb.OleDbDataReader
Dim SqlComm1 As OleDb.OleDbCommand
Dim CON As New OleDbConnection
Dim CustomerIDfromtheTbl As Integer
CON = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=HOTEL-DATABASE.mdf;")
'Check the status of the programs database connection
If Not CON.State = ConnectionState.Open Then
End If
CON.Open()
SqlComm1 = CON.CreateCommand 'This statment will pull the last customer records "customer ID" that was saved on the CustomerEntry Form
SqlComm1.CommandText = "SELECT CustomerID from ReservationsTBL Order By CustomerID DESC"
Rs1 = SqlComm1.ExecuteReader
If Rs1.Read = True Then
CustomerIDfromtheTbl = CInt(Rs1(0)) 'This tells the database that the CustomerID from the Customers Table is now CustIDFromTheTable which is used in my ReservationID
End If
Rs1.Close()
SqlComm1.Connection.Close()
CON.Close()
MsgBox(CustomerIDfromtheTbl)
Try
Me.RESERVATIONTBLTableAdapter.Insert(CStr(CInt(CustomerIDfromtheTbl)), txtLname.Text, txtZipcode.Text, txtPhone.Text, CStr(Today), DateIN.ToString, DateOUT.ToString, txtCreditCard.Text, cboCardType.Text, lblReservationTotal.Text, CInt(cboRoomNumber.ToString), CustomerIDfromtheTbl, lblChargesPerNight.Text, cboRoomType.Text, CStr(CDate(txtCardExpDate.ToString)))
Me.RESERVATIONTBLTableAdapter.Fill(HOTELDATABASE_DATASET.RESERVATIONTBL)
MessageBox.Show("Customer Reservation Sucessfull")
Catch ex As Exception
MessageBox.Show(ex.Message, "Data input error")
End Try
End Sub
End Class
When I try to execute the code, I am getting "File Already in Use" and in the past, since I rewrote this friggn code so many different times, I had also gotten "Jet 4.0... Not registered on this machine" which hasn't been a problem in this example.
I have searched through MANY MSDN articls, GOOGLE and what not.. I am freaking out because this is something that I was supposed to have done last week and I bit off more then I could chew volunteering the use of a database when I didn't need too... but I need the brownie points, so I have to use it.
Can anyone download this and see if it runs on their XP Box or test it on their end?
Thanks a million
~Robb
Attached File(s)
-
HOTEL_PROJECT.zip (806.28K)
Number of downloads: 55
This post has been edited by 4x4pirate: 14 November 2008 - 10:20 AM

New Topic/Question
Reply




MultiQuote




|