dine dine - 3 months ago 20
Vb.net Question

From Access to Textbox

I am beginner for VB.NET. i am trying to retrieve data from Access to clsi.Textbox. i get an syntax error when i run this code.

Syntax error (comma) in query expression 'Roomtype = Classic AND aDate=Monday, August 22, 2016'.

please help

below is my code.

FIRSTDATE is date and time picker

cnn.Open()

cmd1 = New OleDbCommand("select Rate1P from list where Roomtype = " & GroupBox1.Text & " AND aDate=" & FIRSTDATE.Text & "", cnn)

clsi.Text = cmd1.ExecuteNonQuery

cnn.Close()

Answer

Try calling the Value property of the DateTimePicker, not the Text property. Replace FIRSTDATE.Text with FIRSTDATE.Value

Public Class Form1
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        dtp.Value = Date.Now
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MessageBox.Show(dtp.Value)
    End Sub
End Class
Comments