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
70 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
  • 3
  • 3
6 Comments
 
LVL 33

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 33

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now