This is a migrated thread and some comments may be shown as answers.

[Solved] Mapping GUID Columns

1 Answer 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 03 Jul 2009, 10:17 PM
Hi,
 I am using a Combo Box with Grid based on example here: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridcomboajax/defaultcs.aspx?product=grid

For the life of me, I can not get 2 GUID columns to map.  If I leave the DBType to default "object", I get the error "

Conversion failed when converting from a character string to uniqueidentifier".

If I set DBType to "GUID", I get the error "

Guid should contain 32 digits with 4 dashes"

Here is my code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboBox.ascx.cs" Inherits="MyControls_ComboBox" %> 
<div id="productselector"
    Choose Product 
    <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1" 
        DataTextField="Name" DataValueField="ID" Skin="Black" EnableScreenBoundaryDetection="False" 
        EmptyMessage="Choose Product" AppendDataBoundItems="True" AutoPostBack="True"
        <Items> 
            <telerik:RadComboBoxItem Text="All" Value="0" Selected="true" /> 
        </Items> 
    </telerik:RadComboBox> 
</div> 
<div id="grid" style="margin-top: 15px;"
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" GridLines="Horizontal" 
        Width="300px" AllowMultiRowSelection="True" Skin="Black" AllowPaging="True" AllowSorting="True"
        <MasterTableView DataSourceID="SqlDataSource2" AutoGenerateColumns="False"
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="Headline" HeaderText="Headline" SortExpression="Headline" 
                    UniqueName="Headline"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Content" HeaderText="Content" SortExpression="Content" 
                    UniqueName="Content"
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 
</div> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Sitefinity %>" 
    SelectCommand="SELECT Name, ID FROM [sf_lst_NamedList]"></asp:SqlDataSource> 
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Sitefinity %>" 
    SelectCommand="SELECT sf_lst_ListItem.Headline, sf_lst_ListItem.[Content] FROM sf_lst_ListItem INNER JOIN sf_lst_NamedList  
                   ON sf_lst_ListItem.Application = sf_lst_NamedList.Application WHERE (sf_lst_ListItem.ParentID = @ID)"> 
    <SelectParameters> 
        <asp:ControlParameter Name="ID" PropertyName="SelectedValue" ControlID="RadComboBox1" 
            DbType="Guid" /> 
    </SelectParameters> 
</asp:SqlDataSource> 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadComboBox1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="AjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
 
Anyone have any ideas?  Stumped.
thanks.
tom






1 Answer, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 1
answered on 04 Jul 2009, 01:55 PM
I figured it out.  2 things.

1. My query statement was needlessly long.

2.  For whatever reason, SQL Server 2008 and below has a problem (somewhere-don't know where) mapping, reading, inserting GUID in certain situations.  Changing the <SelectParameters> has no effect.  You need to change the GUID to another datatype.

Instead of this:
SELECT x 
FROM 1 
WHERE x = @y 
Where the 'x' value is a GUID datatype.
Do this:
SELECT x 
FROM 1 
WHERE (CAST(x AS varchar(50)) = CAST(@y AS varchar(50))) 
Hope this helps someone.


Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Joe
Top achievements
Rank 1
Share this question
or