Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error: Incorrect syntax near ')'. Help!

    Hello:

    Normally when you received this message is it coming from the db, or the code itself?

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ')'.

    Source Error:

    Line 278: sqlConn.Open()
    Line 279:
    Line 280: dbread = sqlCmd.ExecuteReader()
    Line 281:
    Line 282: Do While dbread.Read()

    Source File: E:\PwrDev\_calendars\calendar.aspx.vb Line: 280

    Codebehind:

    Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

    'Dim calid As Integer = CInt(Page.Request.QueryString("calid"))
    Dim calid As String = 0

    If Page.IsPostBack Then
    calid = CalendarType.Value.ToString
    'CalendarType.SelectedValue = calid
    Else
    calid = Request.QueryString("calid")
    End If

    'If calendartype.Value = "" Then
    'If Not Page.Request.QueryString("calid") = "" Then
    'calid = Page.Request.QueryString("calid")
    'Else
    'calid = CalendarType.Value
    'End If
    'Else
    'calid = CalendarType.Value
    'End If

    calid_value.Text = calid
    calid_value_select.Text = CalendarType.Value.ToString


    Dim sqlConn As SqlConnection
    Dim sqlCmd As SqlCommand
    Dim strConnection As String
    Dim dbread As SqlDataReader
    Dim fieldcount As Integer
    Dim sql
    strConnection = ConfigurationManager.AppSettings("connectionString")
    sqlConn = New SqlConnection(strConnection)

    Dim d As CalendarDay
    Dim c As TableCell
    Dim dbcomm
    Dim DayData
    Dim Color
    d = e.Day
    c = e.Cell
    Dim TheDate = d.Date.ToShortDateString
    current_date = TheDate

    If calid = "0" Then
    sql = "SELECT * FROM Calendar_Events WHERE ((Calendar_Events.StartDate <= '" & TheDate & "') AND (Calendar_Events.EndDate >= '" & TheDate & "')) ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    sql_lbl.text = sql
    Else
    sql = "SELECT * FROM Calendar_Events WHERE (((Calendar_Events.StartDate <= '" & TheDate & "') AND (Calendar_Events.EndDate >= '" & TheDate & "')) AND (Calendar_Events.CalendarID=" & calid & ")) ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    sql_lbl.text = sql
    End If

    sqlCmd = New SqlCommand(sql)
    sqlCmd.Connection = sqlConn
    sqlConn.Open()

    dbread = sqlCmd.ExecuteReader()

    Do While dbread.Read()
    DayData = Left(dbread("Event"), 19) + "<br>"

    If IsMemberLoggedOn <> 1 Then

    If d.IsOtherMonth Then
    c.Controls.Clear()
    Else

    'Color = dbread("Color")
    c.Controls.Add(New LiteralControl("<br><a href=calendar.aspx?EventID=" & dbread("EventID") & "&calid=" & calid & ">" & DayData & "</a>"))
    'c.BackColor=System.Drawing.Color.FromName(Color)
    End If

    Else
    'Color = dbread("Color")
    c.Controls.Add(New LiteralControl("<br><a href=calendar.aspx?EventID=" & dbread("EventID") & "&calid=" & calid & "&member_id=" & MemberId & "&IMS_Login=" & IMSLogin & "&IMS_Password=" & PrivateId & "&IsMemberLoggedOn=" & IsMemberLoggedOn & ">" & DayData & "</a>"))
    'c.BackColor=System.Drawing.Color.FromName(Color)
    End If

    Loop
    dbread.Close()
    sqlConn.Close()

    End Sub

    The page consists of a calendar control and a combobox. when the user click on the item, they will see the event info on the side and there is a textbox where they can enter their e-mail to be reminded of the event. This should just postback to the same page and show the calendar again.

    Any ideas would be great.

    Thanks!
    Robert

  • #2
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try to replace this:
    '" & TheDate & "'

    By this:
    #" & TheDate & "#

    Code:
    If calid = "0" Then
    	Sql = "SELECT * FROM Calendar_Events WHERE Calendar_Events.StartDate <= #" & TheDate & "# AND Calendar_Events.EndDate >= #" & TheDate & "# ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    	sql_lbl.text = Sql
    Else
    	Sql = "SELECT * FROM Calendar_Events WHERE Calendar_Events.StartDate <= #" & TheDate & "# AND Calendar_Events.EndDate >= #" & TheDate & "# AND Calendar_Events.CalendarID=" & calid & " ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    	sql_lbl.text = Sql
    End If
    Last edited by otaku149; 01-11-2007 at 07:38 PM.

  • #3
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by otaku149 View Post
    Try to replace this:
    '" & TheDate & "'

    By this:
    #" & TheDate & "#

    Code:
    If calid = "0" Then
    	Sql = "SELECT * FROM Calendar_Events WHERE Calendar_Events.StartDate <= #" & TheDate & "# AND Calendar_Events.EndDate >= #" & TheDate & "# ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    	sql_lbl.text = Sql
    Else
    	Sql = "SELECT * FROM Calendar_Events WHERE Calendar_Events.StartDate <= #" & TheDate & "# AND Calendar_Events.EndDate >= #" & TheDate & "# AND Calendar_Events.CalendarID=" & calid & " ORDER BY Calendar_Events.StartDate, Calendar_Events.StartTime"
    	sql_lbl.text = Sql
    End If
    Thanks for the quick reply, but that did not seem to help. Could it be a value not being assigned or the statement?

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I believe it's only access when you need the # signs around dates. What is the output of your sql statement when you write it out?

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by binici View Post
    Could it be a value not being assigned or the statement?
    Both, your "TheDate" variable should be a datetime type:

    Dim TheDate as DateTime = e.Day.Date 'or something...

    and then use #" & TheDate & "# to query your db.
    Last edited by otaku149; 01-11-2007 at 08:07 PM.

  • #6
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry my bad, Brando is right, # is used for ms-access database and I am sure that what you are trying to do should be on the DayRender event that way.
    Last edited by otaku149; 01-12-2007 at 03:29 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •