Solved

how to use vb code to insert the value yes\true. anyone can help me???

Posted on 2016-10-20
13
37 Views
Last Modified: 2016-11-21
Dim cnn As New OleDb.OleDbConnection
        Dim cmda As New OleDb.OleDbCommand
        cnn.ConnectionString = datafile
        myConnection.ConnectionString = datafile

        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or ComboBox1.Text = "" Or ComboBox2.Text = "" Then
            MessageBox.Show(" Please fill in all the information", "Information", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)

        Else
            Try

                cnn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Desktop\FYP\VB\Database.accdb")
                Dim command As String
                command = "INSERT INTO ADD_CAR (Reg_ID, CarModel, CarName, Colour, Plate_Number,Rent_Price, Date_Add) VALUES (Reg_ID, CarModel, CarName, Coulour, Plate_Number,Rent_Price, Date_Add)"
                Dim cmd1 As OleDbCommand = New OleDbCommand("INSERT INTO Available FROM ADD_CAR VALUES = 'Yes'")

                cnn.Open()
                Dim cmd As OleDb.OleDbCommand
                cmd = New OleDb.OleDbCommand(command, cnn)
                cmd.Parameters.AddWithValue("Reg_ID", TextBox1.Text)
                cmd.Parameters.AddWithValue("CarModel", ComboBox1.Text)
                cmd.Parameters.AddWithValue("CarName", ComboBox2.Text)
                cmd.Parameters.AddWithValue("Colour", ComboBox3.Text)
                cmd.Parameters.AddWithValue("Plate_Number", TextBox2.Text)
                cmd.Parameters.AddWithValue("Rent_Price", "RM " & TextBox3.Text)
                cmd.Parameters.AddWithValue("Date_Add", DateTimePicker1.Value.Date)


                cmd.ExecuteNonQuery()
            Catch exceptionObject As Exception
                MessageBox.Show(exceptionObject.Message)
            Finally
                cnn.Close()
i want the available has tick
0
Comment
Question by:tang kiat seong
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41853305
Hi,

pls try

cmd.Parameters.AddWithValue("Available", YourBoolean)

Open in new window

Regards
0
 

Author Comment

by:tang kiat seong
ID: 41853332
@Rgonzo1971 cannot the available not tick
0
 
LVL 33

Expert Comment

by:Norie
ID: 41853342
What's the name of the checkbox on the form?
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41853348
then try
cmd.Parameters.Add("Available", SqlDbType.Bit)
cmd.Parameters("Available").Value = 1

Open in new window

1
 

Author Comment

by:tang kiat seong
ID: 41853370
@Rgonzo1971 still cannot
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41853372
Sorry can't help further
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:tang kiat seong
ID: 41853375
@Norie i want he straight auto tick when i add the new car, i no create checkbox in this form
0
 

Author Comment

by:tang kiat seong
ID: 41853377
@Rgonzo1971 nevermine
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 41853533
Perhaps you can do it by adjusting the SQL.
command = "INSERT INTO ADD_CAR (Reg_ID, CarModel, CarName, Colour, Plate_Number,Rent_Price, Date_Add, Avaliable) VALUES (Reg_ID, CarModel, CarName, Coulour, Plate_Number,Rent_Price, Date_Add, 1)"

Open in new window

0
 

Author Comment

by:tang kiat seong
ID: 41853758
@Norie it works,thanks for the help
0
 
LVL 33

Expert Comment

by:Norie
ID: 41853952
No problem, don't forget to mark this solved and indicate the solution.
0
 
LVL 27

Expert Comment

by:Ark
ID: 41854841
Actually it should be:
command = "INSERT INTO ADD_CAR (Reg_ID, CarModel, CarName, Colour, Plate_Number,Rent_Price, Date_Add) VALUES (Reg_ID, CarModel, CarName, Coulour, Plate_Number,Rent_Price, Date_Add, Available)"
Dim cmd As OleDb.OleDbCommand
cmd = New OleDb.OleDbCommand(command, cnn)
cmd.Parameters.AddWithValue("Reg_ID", TextBox1.Text)
'skipped
cmd.Parameters.AddWithValue("Available", YourBooleanValueHere_forExamle_CheckBox1.Checked) 'Added
0
 
LVL 13

Expert Comment

by:frankhelk
ID: 41895628
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Norie (https:#a41853533)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

16 Experts available now in Live!

Get 1:1 Help Now