Solved

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

Posted on 2016-10-20
13
64 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 51

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 34

Expert Comment

by:Norie
ID: 41853342
What's the name of the checkbox on the form?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 51

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 51

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 34

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 34

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot 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‚Ķ

726 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