Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 29th, 2007, 09:47 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default function returns Incorrect syntax

I have a datalist:
  <asp:DataList ID="DataList2" runat="server"
                                     DataSourceID="ObjectDataSource2"
                                      RepeatDirection=Horizontal
                                       RepeatColumns=4 EnableViewState="False" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center">
                                        <ItemTemplate>
   <DIV class=picFrame>
<asp:HyperLink runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "UserID", "profile.aspx?uid={0}") %>' >

       <IMG alt="<%# DataBinder.Eval(Container.DataItem, "Firstname") %>" src="userimages/<%# PickUserGender(DataBinder.Eval(Container.DataItem, "UserPic"),DataBinder.Eval(Container.DataItem, "UserID")) %>" width="80px" height="80px" border=0>
<BR><%# Eval("firstname") %></SPAN>(<%#Eval("friendscount")%>)</asp:HyperLink>
<br /><%# isOnline(DataBinder.Eval(Container.DataItem, "userid")) %></div>


                                        </ItemTemplate>
                                    </asp:DataList>

here is the vb class code:
Public Shared Function PickUserGender(ByVal UserPic As Object, ByVal UserID As Object) As String
            Dim Pic As String
            If IsDBNull(UserPic) Or UserPic = String.Empty Then

                Dim strSQl As String
                Dim dr As SqlDataReader
                Dim cmd As New SqlCommand
                Dim Conn As New SqlConnection
                strSQl = "SELECT UserID,UserPic,Gender FROM Users userid=" & UserID
                Conn = New SqlConnection(ConfigurationManager.ConnectionStrin gs("Conn").ConnectionString)
                cmd = New SqlCommand(strSQl, Conn)
                Conn.Open()
                dr = cmd.ExecuteReader()
                dr.Read()
                If dr.HasRows Then

                    If dr("gender") = "male" Then
                        Pic = "noimage_male.jpg"
                        Return Pic
                    Else
                        Pic = "noimage_female.jpg"
                        Return Pic
                    End If

                End If

                dr.Close()

            Else
                Pic = UserPic
                Return Pic
            End If

        End Function

i get this error:
System.Data.SqlClient.SqlException: Incorrect syntax near '='.









 
Old July 29th, 2007, 10:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Your SQL statement seems to be missing a WHERE clause....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Incorrect syntax near '.' meraj ADO.NET 6 February 27th, 2012 01:01 AM
Incorrect syntax near '!' sinapra Classic ASP Databases 8 August 25th, 2004 02:15 AM
Incorrect syntax near '`' Hez Classic ASP Databases 3 August 5th, 2004 08:13 AM
Incorrect syntax...... Adam H-W Classic ASP Databases 8 June 21st, 2004 11:14 AM
Incorrect SQL Syntax??! ckudrna Access ASP 1 June 5th, 2003 01:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.