Solved

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

Posted on 2016-10-20
13
56 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 50

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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 50

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 50

Expert Comment

by:Rgonzo1971
ID: 41853372
Sorry can't help further
0
 

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 28

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 14

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

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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