1

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

5
  • Look at my answer here. Maybe it helps Commented Jul 11, 2011 at 7:53
  • What do your parameters in the <asp:SqlDataSource> look like?? Commented Jul 11, 2011 at 7:57
  • see above..it is writen @UserID Commented Jul 11, 2011 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" Commented Jul 11, 2011 at 7:58
  • Reniuz, it doesnt help. marc..see update above Commented Jul 11, 2011 at 8:01

2 Answers 2

3
<SelectParameters>
                <asp:Parameter Name="UserID" Type="Guid"  />
     </SelectParameters> 

Updated Code

<asp:Parameter Name="UserID" Type="Object" />
<asp:Parameter Name="MemberID" DbType="Guid" />
7
  • 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 Commented Jul 11, 2011 at 8:07
  • Type doesnt have such a property such as a Guid Commented Jul 11, 2011 at 8:08
  • Can you specify the type with the corresponding namespace? Commented Jul 11, 2011 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 Commented Jul 11, 2011 at 8:10
  • No!! I cant it wont let me write ..Type="System.Guid" Commented Jul 11, 2011 at 8:11
1

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> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.