Solved

i want to booking the car. how to change the available to no and transfer the data into booking table

Posted on 2016-10-23
6
96 Views
Last Modified: 2016-11-09
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ComboBox1.Text = "" Or ComboBox2.Text = "" Or TextBox1.Text = "" Or TextBox4.Text = "" Or rentbox.Text = "" Or totalbox.Text = "" Or daytxt.Text = "" Then
            MessageBox.Show(" Please fill in all the information", "Information", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)

        Else
            Try
                myConnToAccess = New OleDbConnection("provider=microsoft.ACE.oledb.12.0; data source=C:\Users\User\Desktop\FYP\VB\Database.accdb")
                myConnToAccess.Open()
                Dim command As String
                command = "INSERT INTO BOOKING (Username,CarName,Colour,Plate_Number,Rent_Price,Days,Pick_Up_Date,Return_Date,Total_Amount) VALUES (Username,CarName,Colour,Plate_Number,Rent_Price,Days,Pick_Up_Date,Return_Date,Total_Amount)"
                Dim cmd As OleDb.OleDbCommand
                cmd = New OleDb.OleDbCommand(command, myConnToAccess)
                cmd.Parameters.AddWithValue("Username", ComboBox1.Text)
                cmd.Parameters.AddWithValue("CarName", ComboBox2.Text)
                cmd.Parameters.AddWithValue("Colour", TextBox1.Text)
                cmd.Parameters.AddWithValue("Plate_Number", TextBox4.Text)
                cmd.Parameters.AddWithValue("Rent_Price", rentbox.Text)
                cmd.Parameters.AddWithValue("Days", daytxt.Text)
                cmd.Parameters.AddWithValue("Pick_Up_Date", DateTimePicker1.Value.Date)
                cmd.Parameters.AddWithValue("Return_Date", DateTimePicker2.Value.Date)
                cmd.Parameters.AddWithValue("Total_Amount", totalbox.Text)

                cmd.ExecuteNonQuery()
            Catch exceptionObject As Exception
                MessageBox.Show(exceptionObject.Message)
            Finally
                myConnToAccess.Close()
                MessageBox.Show(" Booking Successful!", " Register Information ", MessageBoxButtons.OK, MessageBoxIcon.Information)

            End Try
        End If
    End SubCapture5.JPG
0
Comment
Question by:tang kiat seong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 41855961
To change Available to No you'll need an UPDATE query.

What's the name of the table with the Available field in it?

What's it's primary key? Is that primary key available on the form?
0
 

Author Comment

by:tang kiat seong
ID: 41856056
@Norie Reg_ID is the primary key.
what i want is when the car in booking the available change to not
0
 
LVL 34

Expert Comment

by:Norie
ID: 41856058
You would need an UPDATE query like this then,
command = "UPDATE [i]yourtablename[/i] SET Available = 0 WHERE Reg_ID = '" & txtRegID.Text & "';"

Open in new window

where Reg_ID is coming from the textbox txtRegID.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tang kiat seong
ID: 41856098
if in the return car also use same command?
0
 
LVL 34

Accepted Solution

by:
Norie earned 500 total points
ID: 41856107
Not sure what you mean.

If you want to change Available to Yes when the car is returned you would use something like this.
command = "UPDATE [i]yourtablename[/i] SET Available = 1 WHERE Reg_ID = '" & txtRegID.Text & "';"

Open in new window

0
 

Author Comment

by:tang kiat seong
ID: 41880435
@Norie about the return table i using same code but didn't work...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question