Solved

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

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

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 49

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 49

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 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 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get distinct values from excel or comm seperated file 4 25
Request to review costing formula 3 36
Formula Help 3 22
ProperCase in Excel (Sheet) 3 13
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

809 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