开发者

Converting string to UniqueIdentifier - asp.net SQL search based on asp:Label

开发者 https://www.devze.com 2023-02-19 07:36 出处:网络
Hi I\'m currently trying to perform a search using my SQLDataSource but want to use the WHERE statement to find the GUID that I have already assigned to a Label, however I\'m getting the error \"Conve

Hi I'm currently trying to perform a search using my SQLDataSource but want to use the WHERE statement to find the GUID that I have already assigned to a Label, however I'm getting the error "Conversion failed when converting from a character string to uniqueidentifier".

开发者_开发百科Ive been reading through forums just like this for days now and I'm just getting myself into all sorts of mess with code, Ive tried using C# in the codebehind based on SqlSelecting and buttons to populate the ListView that Im working with, ListView_Selecting etc etc

I'm pretty new to asp.net and C# so maybe I've not understood some of the forums Ive been on, either way I'd appreciate any and all help anyone can give, I've included the code below.

Thanks in advance.

(NESTED WITHIN ANOTHER LISTVIEW)

<asp:Label  ID="CommId" Text='<%# Eval("CommentId") %>' runat="server"  Visible="false"></asp:Label>

<asp:ListView ID="viewComments1" DataSourceID="AddCommentsSource" runat="server">
            <LayoutTemplate> <span ID="itemPlaceholder" runat="server" />
            </LayoutTemplate>
            <ItemTemplate>

              <asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("Comment") %>/> 
                <asp:Label ID="CommentDateLabel" runat="server" Text='<%# Eval("CommentDate") %>' />
            </ItemTemplate>
            </asp:ListView>



<asp:SqlDataSource ID="AddCommentsSource" runat="server"  
         ConnectionString="<%$ ConnectionStrings:SecurityTutorialsConnectionString %>" 
           SelectCommand="SELECT myComment.Comment, myComment.CommentDate, aspnet_Users.UserName FROM aspnet_Users, myComment, GuestbookComments
           WHERE myComment.CommentId = 'CommId' AND aspnet_Users.UserId = myComment.UserId
            ORDER BY myComment.CommentDate DESC" >   
          </asp:SqlDataSource>


I'd suggest using code-behind to dynamically issue your query based on your parameters, also use named parameters for convenience and safety. As for converting a string to a GUID, then it's fairly simple:

Guid yourGuid = new Guid(yourString);
0

精彩评论

暂无评论...
验证码 换一张
取 消