Sql + .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neha2007
    New Member
    • Jun 2007
    • 2

    #1

    Sql + .net

    I am trying to use a MS Access Database in an vb.aspx page.

    I have written the following two queries.. but they are giving me errors which i am unable to fix.ANy help in this regard would be highly appreciated .

    Query 1: Dim sSQL As String = "UPDATE AuthorTable" & _
    " SET ID ='" & sID & "',Name = '" & sName & "',BookID ='" & sID & "',Date ='" & sDate & ""

    It gives me the error: Syntax error in string in query expression '''.
    I understand that there is probably a problem with the way I am ending the query. But I do not understand what would be the correct syntax. Please Help.

    Query 2:
    Dim sSQL As String = "SELECT COUNT(*)" & _
    "FROM (" & _
    "SELECT DISTINCT LastName" & _
    " FROM Authors" & _
    "WHERE Month = '" & sMonth & "' AND ID = '" & sID & "')"

    Error: Operator '&' is not defined for string "SELECT COUNT(*)FROM (SELECT DIST" and type 'ListItem'.

    Would really appreciate a quick response.

    Thanks
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by neha2007
    I am trying to use a MS Access Database in an vb.aspx page.

    I have written the following two queries.. but they are giving me errors which i am unable to fix.ANy help in this regard would be highly appreciated .

    Query 1: Dim sSQL As String = "UPDATE AuthorTable" & _
    " SET ID ='" & sID & "',Name = '" & sName & "',BookID ='" & sID & "',Date ='" & sDate & ""

    It gives me the error: Syntax error in string in query expression '''.
    I understand that there is probably a problem with the way I am ending the query. But I do not understand what would be the correct syntax. Please Help.

    Query 2:
    Dim sSQL As String = "SELECT COUNT(*)" & _
    "FROM (" & _
    "SELECT DISTINCT LastName" & _
    " FROM Authors" & _
    "WHERE Month = '" & sMonth & "' AND ID = '" & sID & "')"

    Error: Operator '&' is not defined for string "SELECT COUNT(*)FROM (SELECT DIST" and type 'ListItem'.

    Would really appreciate a quick response.

    Thanks
    Hi!

    I strongly recommend that you use parameters to set your values.
    Check out the .NET article how to use a database in your program . I think that one of your variables might be null and its trying to add "" to the sql query...which isn't allowed.

    Comment

    Working...