Hi,
IF I run my application was created in vb.net,
it Shows an error like "Incorrect syntax near '3/15/2013 12:00:00 AM'."
I neeed to Display the data in Gridview Based on date..
The code is

Private Sub File_Request_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Form1.Visible = False
    from_date = appdate.Value.ToString("")
    CON.Open()
    CMD = New SqlCommand("select * from table_name '" + from_date + "'", CON)
    sda = New SqlDataAdapter(CMD)
    ds = New DataSet()
    sda.Fill(ds)
    CON.Close()
    GRIDREQUEST.DataSource = ds.Tables(0)

    GRIDREQUEST.Enabled = True

End Sub

If you are using Access the correct syntax is

SELECT * FROM table WHERE datefield = #datevalue#

otherwise use

SELECT * FROM table WHERE datefield = 'datevalue'

I try this also,

CMD = New SqlCommand("select * from table_name '" & Format(from_date, "yyyy-MMM-dd") & " 00:00:00' ", CON)

Actually,I'm Confusing where should this error was coming,Kindly Suggest any idea.

Edited 3 Years Ago by pritaeas: Added markdown

Hi,

Like ReverendJim says.. change the SQL statement.. write "Where and filedname..."

CMD = New SqlCommand("select * from table_name WHERE Field_Name =#" _
    & Format(from_date, "yyyy-MMM-dd") & "# ", CON)

Regards
Veena

I change the code to Like Reverendjim,But now it shows "Syntax error converting datetime from character string.".I try to Solve myself,But If u have any idea kindly suggest me..

error-->Syntax error converting datetime from character string

    That code is "CMD = New SqlCommand("select * from mrd_onlinerequest WHERE MRD_REQDATE = 'from_date'", CON)


     CMD = New SqlCommand("select * from mrd_onlinerequest WHERE MRD_REQDATE =#" & Format(from_date, "yyyy-MMM-dd") & "# ", CON)

This time i try your code,It Shows
error-->Invalid column name '#yyyy'. Invalid column name 'MMM'. Invalid column name 'dd#'

Edited 3 Years Ago by pearl.kumar1: test

Hi,

Try this:

CMD = New SqlCommand("select * from mrd_onlinerequest WHERE MRD_REQDATE = '" _
    & Format(from_date, "yyyy-MMM-dd") & "' ", CON)

Regards
Veena

Actual code is

     Private Sub File_Request_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    from_date = appdate.Value.ToString("")
    CON.Open()
    CMD = New SqlCommand("select * from mrd_onlinerequest WHERE MRD_REQDATE = '" _
 & Format(from_date, "yyyy-MMM-dd") & "' ", CON)
    'CMD = New SqlCommand("select * from patient WHERE regdatetime = 'from_date'", CON)
    sda = New SqlDataAdapter(CMD)
    ds = New DataSet()
    sda.Fill(ds)
    CON.Close()
    GRIDREQUEST.DataSource = ds.Tables(0)

    GRIDREQUEST.Enabled = True

error-->"Syntax error converting datetime from character string.

APPDATE IS DATETIMEPICKER AND DECLARED AS DATETIME..

Edited 3 Years Ago by pearl.kumar1: TEST

Try

CMD = New SqlCommand("SELECT * FROM mrd_onlinerequest " & _
                     " WHERE MRD_REQDATE = '" & appdate.Value.Date & "'", con)
This article has been dead for over six months. Start a new discussion instead.