Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-10-20
13
Medium Priority
?
74 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
[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
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 53

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 35

Expert Comment

by:Norie
ID: 41853342
What's the name of the checkbox on the form?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 53

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 53

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 35

Accepted Solution

by:
Norie earned 2000 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 35

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 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