Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Part of the sqldatasource parameters:

            <asp:SqlDataSource ID="AllQuestionAskedDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" SelectCommand="SELECT ThreadTitle
FROM Threads
WHERE UsersID=@UserID">
                <SelectParameters>
                    <asp:Parameter Name="UserID" />
                </SelectParameters>
            </asp:SqlDataSource>

The code behind:

 Guid userid = UsefulStaticMethods.GetUserNameFromUserGuid(name);
 AllQuestionAskedDataSource.SelectParameters["UserID"].DefaultValue = userid;

It tells me that it cant convert userid from Guid to string. But the parameter must be a Guid for the select statement of the sqldatasource to work

share|improve this question
    
Look at my answer here. Maybe it helps –  Reniuz Jul 11 '11 at 7:53
    
What do your parameters in the <asp:SqlDataSource> look like?? –  marc_s Jul 11 '11 at 7:57
    
see above..it is writen @UserID –  WithFlyingColors Jul 11 '11 at 7:57
    
Yeah I see that - but inside your <asp:SqlDataSource> you should have more content - a <SelectParameters> section etc. - that's where it would be defined what data type a parameter is.... most likely, this is set to "string" while you want to pass a "guid" –  marc_s Jul 11 '11 at 7:58
    
Reniuz, it doesnt help. marc..see update above –  WithFlyingColors Jul 11 '11 at 8:01

2 Answers 2

up vote 3 down vote accepted
<SelectParameters>
                <asp:Parameter Name="UserID" Type="Guid"  />
     </SelectParameters> 

Updated Code

<asp:Parameter Name="UserID" Type="Object" />
<asp:Parameter Name="MemberID" DbType="Guid" />
share|improve this answer
    
Error 3 Cannot create an object of type 'System.TypeCode' from its string representation 'Guid' for the 'Type' property. D:\Documents and Settings\Dima\My Documents\Visual Studio 2010\WebSites\WebSite10\Statistics.aspx 19 –  WithFlyingColors Jul 11 '11 at 8:07
    
Type doesnt have such a property such as a Guid –  WithFlyingColors Jul 11 '11 at 8:08
    
Can you specify the type with the corresponding namespace? –  Saanch Jul 11 '11 at 8:09
    
Error 3 Cannot create an object of type 'System.TypeCode' from its string representation 'Guid' for the 'Type' property. D:\Documents and Settings\Dima\My Documents\Visual Studio 2010\WebSites\WebSite10\Statistics.aspx 19 –  WithFlyingColors Jul 11 '11 at 8:10
    
No!! I cant it wont let me write ..Type="System.Guid" –  WithFlyingColors Jul 11 '11 at 8:11

You could simply write your custom parameter:

public class UserIdParameter : Parameter
{
    protected override object Evaluate(HttpContext context, 
        System.Web.UI.Control control)
    {
        var name = GetName();
        return UsefulStaticMethods.GetUserNameFromUserGuid(name);

    }
}

<SelectParameters>
        <custom:UserIdParameter Name="UserID" />
</SelectParameters> 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.