"File in Use" error (Vista, VB.NET & Database.MDF)

I really want to cry at this point.. lol

Page 1 of 1

9 Replies - 4529 Views - Last Post: 17 November 2008 - 10:16 AM Rate Topic: -----

#1 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

"File in Use" error (Vista, VB.NET & Database.MDF)

Posted 14 November 2008 - 09:47 AM

Ok,

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)


This post has been edited by 4x4pirate: 14 November 2008 - 10:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: "File in Use" error (Vista, VB.NET & Database.MDF)

#2 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 14 November 2008 - 03:30 PM

I DL it and took a peek, this is why I hate Microsoft binding crap, I consider myself a decent programmer but when I see all these DATASET, BindingSource, TableAdapter, TableADapterManager... my head explodes. Something so simple becomes a bloated mess.

The problem you are having is that your MDF file is a SQLServer database and not a MS Access database, you should really not be opening a connection up as an OLEDB JET 4.0 datasource. Nor should you be using OleDbConnection or OLEDBReaders. You may also want to change User Instance=False. I would also consider a normal SQL database instead of an attached one as well.

I love the effort, and really wish I could sit down with you for a week and get you heading in the right direction with this project as it needs alot of work. I have written some code that will get you that ID, however it is not the proper approach to the problem and it should not be used in a production system. You will need modify the connection strings path to the mdf file based on its location on your system (hardcoded paths are a bad thing as well).

***DO NOT USE THIS CODE, I FOUND THE PROPER SOLUTION BELOW, BUT USE IT AS AN EXAMPLE IN THE FUTURE***
        Dim CustomerIDfromtheTbl As Integer
        Using Conn As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=PATHTOFILENEEDTOGOHERE\HOTEL-DATABASE.mdf;Integrated Security=True;User Instance=True")
            Conn.Open()
            Using Command As New SqlClient.SqlCommand("SELECT CustomerID from CustomerTBL Order By CustomerID DESC", Conn)
                Using Reader As Data.SqlClient.SqlDataReader = Command.ExecuteReader
                    'Your logic
                    If Reader.Read Then
                        CustomerIDfromtheTbl = Reader.GetInt32(0)
                    End If
                End Using
            End Using
        End Using



Because you are using SQL and you have the identity set , the databinding crap should be picking up the new IDs for you, there is no need to be pulling them on your own. The reservation form should be open for the selected customer, so you should be passing a reference of the customer to the form. From there you can grab the customerID.

So I looked at your customer entry code, and noticed you are using insert, instead you want to create a new row and ADD it to the dataset then use the adapters update function to update the row. This will return the new customer id, i placed it in a messagebox. You will have to put it to use, i recommend added a public populate rountine to the reservation form with a customertblrow as a parameter, then simply pass it the newRow and update the textboxs from within the populate routine.

  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

            Dim newRow As HOTELDATABASE_DATASET.CUSTOMERTBLRow
            newRow = HOTELDATABASE_DATASET.CUSTOMERTBL.NewCUSTOMERTBLRow
            With newRow
                .CustomerFname = txtFname.Text
                .CustomerLname = txtLname.Text
                .CustomerAddress1 = txtAddress1.Text
                .CustomerAddress2 = txtAddress2.Text
                .CustomerCity = txtCity.Text
                .CustomerState = cboSelectState.Text
                .CustomerZip = txtZipcode.Text
                .CustomerEntryDate = Now.ToString
                .CustomerPhone = txtPhone.Text
                .CustomerEmail = txtEmail.Text
            End With
            HOTELDATABASE_DATASET.CUSTOMERTBL.AddCUSTOMERTBLRow(newRow)

            Me.CUSTOMERTBLTableAdapter.Update(newRow)


            '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)

            MsgBox(newRow.CustomerID)
            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



There must be a cleaner way to manager adapters across all your forms, I just don't use them so I don't know what to recommend.

This post has been edited by magicmonkey: 14 November 2008 - 03:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 14 November 2008 - 04:07 PM

Well I played around with it a bit more and noticed that you did bind all the textboxs to the dataadapter, so you can make it even simpler...

**I did have to change the zip code field to update on validation

Public Class frm2CustomerEntry

    Private Sub frm2CustomerEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CUSTOMERTBLBindingSource.AddNew() 'Add New Record
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim drv As DataRowView = DirectCast(CUSTOMERTBLBindingSource.Current, DataRowView) 'Get Current Record
        drv("CustomerEntryDate") = Now.ToString 'Set Entry Date as you don't have field on form
        CUSTOMERTBLBindingSource.EndEdit() 'End Add New Edit
        CUSTOMERTBLTableAdapter.Update(HOTELDATABASE_DATASET.CUSTOMERTBL) 'Update the table to get new customer ID
        MsgBox(drv("CustomerID")) 'Here it is!
    End Sub

'....



Oh and curse you for making me learn how to databind forms!!!
Was This Post Helpful? 0
  • +
  • -

#4 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 16 November 2008 - 12:32 PM

Just getting back to this now... had to get away for the weekend.... my wife was going nuts with me staying up till 3:30 every morning trying to beat down this MS access/SQL Database issues. I had written it so many times.. trying to figure out what I did wrong...


I created an accessDB the second time, which uses the jet4.o bit.. but I will go back to using this code..

I will let you know in a few. THANK you for all of your help..
Was This Post Helpful? 0
  • +
  • -

#5 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 16 November 2008 - 01:12 PM

Problem I still run into is the whole "File in Use" when I submit the reservations form :(

I attached the latest file.. Attached File  HOTEL_PROJECT_updated.zip (874.55K)
Number of downloads: 59

This post has been edited by 4x4pirate: 16 November 2008 - 01:19 PM

Was This Post Helpful? 0
  • +
  • -

#6 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 16 November 2008 - 03:42 PM

working on something.. I will post shortly on my status :)
Was This Post Helpful? 0
  • +
  • -

#7 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 16 November 2008 - 04:54 PM

magicmonkey I TOTALLY OWE YOU BIGTIME!!!!!


OMG.. I am finally past this friggin hurdle!! I love you man!!!.. haha



I have to clean the code up a little and format some stuff but I am now ready to move on to the next portion of the project..

I have been struggling for this for literally, 2 weeks.. THANK you SO MUCH!!!


here is my code if anyone is interested:


Public Class frm2CustomerEntry


	Private Sub frm2CustomerEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		CUSTOMERTBLBindingSource.AddNew() 'Add New Record  

	End Sub

	Private Sub btnSaveCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveCustomer.Click
		Dim drv As DataRowView = DirectCast(CUSTOMERTBLBindingSource.Current, DataRowView) 'Get Current Record  


		drv("CustomerEntryDate") = Now.ToString 'Set Entry Date as you don't have field on form  
		'CUSTOMERTBLBindingSource.EndEdit() 'End Add New Edit  
		CUSTOMERTBLTableAdapter.Update(HOTELDATABASE_DATASET.CUSTOMERTBL) 'Update the table to get new customer ID  
		MsgBox(drv("CustomerID")) 'Here it is!  
		Dim newCustomerRow As HOTELDATABASE_DATASET.CUSTOMERTBLRow
		newCustomerRow = HOTELDATABASE_DATASET.CUSTOMERTBL.NewCUSTOMERTBLRow

		'--- Throws data into the customer database ---------------------------------------------------------------------  

		Try
			Dim newRow As HOTELDATABASE_DATASET.CUSTOMERTBLRow
			newRow = HOTELDATABASE_DATASET.CUSTOMERTBL.NewCUSTOMERTBLRow
			With newRow

				'.CustomerEntryDate = Now.ToString
				.CustomerFname = txtFname.Text
				.CustomerLname = txtLname.Text
				.CustomerAddress1 = txtAddress1.Text
				.CustomerAddress2 = txtAddress2.Text
				.CustomerCity = txtCity.Text
				.CustomerState = cboSelectState.Text
				.CustomerZip = txtZipcode.Text
				.CustomerEntryDate = Now.ToString
				.CustomerPhone = txtPhone.Text
				.CustomerEmail = txtEmail.Text
			End With
			HOTELDATABASE_DATASET.CUSTOMERTBL.AddCUSTOMERTBLRow(newRow)
			Me.CUSTOMERTBLTableAdapter.Update(newRow)
			MsgBox(newRow.CustomerID)
		Catch ex As System.Exception
			MessageBox.Show(ex.Message, "Data input error")
		End Try
		Me.CUSTOMERTBLTableAdapter.Dispose()
		Me.CUSTOMERTBLTableAdapter.Connection.Close()
		Me.Close()
		frm3Reservations.Show()


	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




Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data

Public Class frm3Reservations

	Dim strNumberofnights As Date

	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

	'*********** FORM LOAD ***********************************************************************************
	Private Sub frm3Reservations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Try
			Me.CUSTOMERTBLTableAdapter.QueryByLastCustomerEntered(Me.HOTELDATABASE_DATASET.CUSTOMERTBL)
		Catch ex As System.Exception
			System.Windows.Forms.MessageBox.Show(ex.Message)
		End Try

	
		Me.RESERVATIONTBLTableAdapter.Fill(Me.HOTELDATABASE_DATASET.RESERVATIONTBL)
		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

	'*********** CHECK IN *************************************************************************************
	Private Sub DateTimeCheckIn_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimeCheckIn.ValueChanged
		If DateTimeCheckIn.Value < Today Then									 ' This code sets the the calendars
			MessageBox.Show("Check-IN Date is earlier than Today" & _
							("Please change the Check-In Time to Today or later"))	  ' To accept only a max of 1.5 years
		ElseIf DateTimeCheckIn.Value = Today.AddDays(553) Then					' in advance of the current date
			MessageBox.Show("Maximum of 1.5 years reservation allowance," & _
							("Please make sure date is less than 1.5 years from Today")) ' Since I changed the calendar after I wrote the code 
		Else																			 ' to look at the DatePicker calendar with minimum's and maximum's
			DateIN = DateTimeCheckIn.Value			' You should never see this error. 
			DateTimeCheckOut.MinDate = DateTimeCheckIn.Value.AddDays(1)
			DateTimeCheckOut.MaxDate = DateTimeCheckIn.Value.AddDays(552)
		End If																		   '
		'************************************************************************************************************************************************************
		DateTimeCheckIn.Text = DateIN.ToString
		DateTimeCheckOut.Value = DateTimeCheckIn.Value.AddDays(1) 'Changes the DatePicker for Checked Out +1 day ahead of checked in
		DateOUT = DateTimeCheckOut.Value 'This makes sure that the day after the next day will 
		DateTimeCheckOut.Text = DateTimeCheckOut.Value.ToString
		'************************************************************************************************************************************************************
		lblNumberOfNights.Text = ("")
		lblReservationTotal.Text = ("")
		'************************************************************************************************************************************************************

	End Sub

	'*********** CHECK OUT *************************************************************************************
	Private Sub DateTimeCheckOut_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimeCheckOut.ValueChanged
		DateTimeCheckOut.MinDate = DateTimeCheckIn.Value.AddDays(1)
		DateTimeCheckOut.MaxDate = Today.AddDays(552) 'Reservation up to 1.5 years from current date
		DateOUT = DateTimeCheckOut.Value

		If DateTimeCheckOut.Value = Today.AddDays(553) Then
			MessageBox.Show("Maximum of 1.5 years reservation allowance," & _
							("Please make sure date is less than 1.5 years from Today"))
			DateOUT = Today
			DateTimeCheckOut.Text = DateIN.ToString

		End If
		If DateOUT <= Today Then
			MessageBox.Show("Minimum of 1 day beyond Check-In date is required" & _
							("Please change the Check-Out Time"))
			DateIN = Today.AddDays(1) ' if todays date is greater, this sets date out to date in + 1 day
			DateTimeCheckOut.Text = DateOUT.ToString
		Else
			DateOUT = DateTimeCheckOut.Value
		End If
	End Sub

	'*********** SUBMIT RESERVATION **************************************************************************
	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 newReservationRow As HOTELDATABASE_DATASET.RESERVATIONTBLRow
		newReservationRow = HOTELDATABASE_DATASET.RESERVATIONTBL.NewRESERVATIONTBLRow
		'--- Throws data into the customer database ---------------------------------------------------------------------  

		Try
			Dim newRow As HOTELDATABASE_DATASET.RESERVATIONTBLRow
			newRow = HOTELDATABASE_DATASET.RESERVATIONTBL.NewRESERVATIONTBLRow
			With newRow

				.ReservationFname = txtFname.Text
				.ReservationLname = txtLname.Text
				.ReservationZip = txtZipcode.Text
				.ReservationCreatedDate = Now.ToString
				.ReservationPhone = txtPhone.Text
				.ReservationDateIN = CStr(CDate(DateIN.ToString))
				.ReservationDateOut = CStr(CDate(DateOUT.ToString))
				.ReservationCreditCard = txtCreditCard.Text
				.ReservationCCardType = cboCardType.Text
				.ReservationCCardExpDate = txtCardExpDate.Text
				.ReservationTotal = lblReservationTotal.Text
				.ReservationRoomNumber = cboRoomNumber.Text
				.ReservationRoomType = cboRoomType.Text
				.ReservationCustomerID = CInt(txtCustomerID.Text)
				.ReservationRoomCost = cboRoomCost.Text
			End With
			HOTELDATABASE_DATASET.RESERVATIONTBL.AddRESERVATIONTBLRow(newRow)
			Me.RESERVATIONTBLTableAdapter.Update(newRow)
			MsgBox(newRow.ReservationID)
		Catch ex As System.Exception
			MessageBox.Show(ex.Message, "Data input error")
		End Try
		Me.RESERVATIONTBLTableAdapter.Dispose()
		Me.RESERVATIONTBLTableAdapter.Connection.Close()
		Me.Close()
		'--- Throws data into the customer database ---------------------------------------------------------------------  

































	End Sub

	'*********** CALCULATE RESERVATION **************************************************************************
	Private Sub btnCalculateReservation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateReservation.Click
		Dim RoomCostToDbl, RoomCostByNights As String
		Dim RoomNumNights As Integer
		Dim CalculateDays As String

		CalculateDays = CStr(DateOUT.Subtract(DateIN).Days)
		lblNumberOfNights.Text = CalculateDays.ToString
		RoomNumNights = CInt(lblNumberOfNights.Text)
		RoomCostToDbl = CStr(CDbl(cboRoomCost.Text))
		RoomCostByNights = CStr(CDbl(RoomCostToDbl) * RoomNumNights)

		lblReservationTotal.Text = RoomCostByNights.ToString

	End Sub


End Class


Was This Post Helpful? 0
  • +
  • -

#8 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 16 November 2008 - 07:51 PM

Well the last post I had showed you how to use the binding of the textboxes to add the record, so there is no need to have all the manual code under it... the .endinit saves the values in the textboxes all on its own...

 Private Sub btnSaveCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveCustomer.Click
        Dim drv As DataRowView = DirectCast(CUSTOMERTBLBindingSource.Current, DataRowView) 'Get Current Record  
        drv("CustomerEntryDate") = Now.ToString 'Set Entry Date as you don't have field on form  

'You do need this to save the textboxes, as noted above one of you fields databindings was not set to update on validation thou        
CUSTOMERTBLBindingSource.EndEdit() 'End Add New Edit  

        CUSTOMERTBLTableAdapter.Update(HOTELDATABASE_DATASET.CUSTOMERTBL) 'Update the table to get new customer ID  
        MsgBox(drv("CustomerID")) 'Here it is!  

'Don't need all the crap that was here because you binded all the form textboxes to the fields already!

        Me.Close()
        frm3Reservations.Show()


    End Sub





Was This Post Helpful? 0
  • +
  • -

#9 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 17 November 2008 - 09:17 AM

How would I go about setting up a masked text box and a "Search" button that would execute a query to search for customer by their phone number?


I know how to logically setup a querry, its taking the filed and adding the execute button I have a problem with.. lol.
Was This Post Helpful? 0
  • +
  • -

#10 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: "File in Use" error (Vista, VB.NET & Database.MDF)

Posted 17 November 2008 - 10:16 AM

I would use a SQLCommand object and either create a parameterized query or stored procedure.

However since you are using a DATASET object, open the HOTELDATABASE_DATASET.xsd and right click on customertbl, select Add>Query and you can build a query within the dataset that will generate the code for you. In the query builder you simply enter a parameter name in the CustomerPhone fields FILTER column, such as @PhoneNumber, it must start with the @ to work as a parameter.

If you do the above then you can simply do the following...
        Dim Data As HOTELDATABASE_DATASET.CUSTOMERTBLDataTable = CUSTOMERTBLTableAdapter.GetDataBy("5555555")



If you are going to use the dataset and dataadapters for databindings then you should try to stick with it throughout the project.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1