Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Trying to avoid booking a lesson twice on the same date and same time.
got this code from youtube but it's not working for time. If i change to @name or something other than time it will work. please help

What I have tried:

Imports System.Data.OleDb

Public Class Form1

    Dim myconnstring As String = "Provider= Microsoft.Jet.OleDb.4.0;Data source=" & Environment.CurrentDirectory & "Carst.mdb"
    Dim command As OleDbCommand
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the '' table. You can move, or remove it, as needed.

    End Sub

    Private Sub Savebtn_Click(sender As Object, e As EventArgs) Handles Savebtn.Click
        Dim myconnection As New OleDbConnection(myconnstring)
        If Car_IdTextBox.Text = "" Or TimeDateTimePicker.Text = "" Then
            MsgBox("Please fill in the time and Car Id")

            Dim theQuery As String = "select *from cars where Time=@Time"
            Dim mycommand As New OleDbCommand(theQuery, myconnection)
            mycommand.Parameters.AddWithValue("@Time", TimeDateTimePicker)
            'mycommand.Parameters.AddWithValue("@day", Dayd)
            Dim myReader As OleDbDataReader = mycommand.ExecuteReader()
            If myReader.HasRows Then
                MsgBox("Already Booked", MsgBoxStyle.Exclamation, "Find some other time")

                Form1_Load(Me, e)
            End If
        End If

    End sub
Updated 24-Jul-18 2:47am

Start be reading the code and working out what it does, and how it does it.
It's fine and dandy to find code on the internet, but if you don't want it to do exactly what it did in that application, you will always need to modify it to suit your needs. And that means understanding how it works, not asking someone else to do your homework for you.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements."[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself.
Share this answer
What is TimeDateTimePicker?
If that is a DateTimePicker Class (System.Windows.Forms)[^], use TimeDateTimePicker.Value to get the value as DateTime object.

Note also that TIME is a reserved word and must be therefore enclosed by square brackets when used as field or table name (which should be generally avoided):
Dim theQuery As String = "SELECT * FROM cars WHERE [Time]=@Time"
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900