Asp.Net Conversion failed when converting from a character string to uniqueidentifier.

westdh
westdh used Ask the Experts™
on
this is my string:
            SelectCommand="SELECT '' as UserId, '' as [Company], '' as [WebSiteUrl] UNION SELECT UserId, Company, WebSiteUrl FROM [UserProfile] ORDER BY [Company]">

this is my error:
--------------------------------------------------------------------------------

Conversion failed when converting from a character string to uniqueidentifier.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier.
----------------------------------------------------------------------------------

this portion of my code:  can be: '' as UserId or '0' as UserId that for a string or a int
I do not know what it would take to convert the Guid to a string as to replace '' as UserId.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Reza RadConsultant, Trainer

Commented:
try this:

SelectCommand="SELECT "+Guid.Empty.ToString()+" as UserId, '' as [Company], '' as [WebSiteUrl] UNION SELECT UserId, Company, WebSiteUrl FROM [UserProfile] ORDER BY [Company]"

Author

Commented:
I got an error:

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

Source Error:


Line 45:                   <br />
Line 46:                   <br />
Line 47:                   <asp:SqlDataSource ID="SqlDataSource1" runat="server" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"  
Line 48:              SelectCommand="SELECT "+Guid.Empty.ToString()+" as UserId, '' as [Company], '' as [WebSiteUrl] UNION SELECT UserId, Company, WebSiteUrl FROM [UserProfile] ORDER BY [Company]"
Line 49:                   </asp:SqlDataSource>
 
--------------------------------------------------------------------------------------------------------------------

and the compiler error:
Error      4      The server tag is not well formed.      C:\WebSite2\Master.aspx      47

the "+Guid.Empty.ToString()+" as UserId      
Guid.Empty.ToString() -> this portion of the line as a red under line & commented

Valuation (asp.net): The attribute must be followed by an equal sign (=) and a value. if the value is in quotation marks, the quotation marks must match.

Author

Commented:
this line where i changed the double qoutation marks to single run with no complier error but I still get a server error.

SelectCommand="SELECT '+Guid.Empty.ToString()+' as UserId, '' as [Company], '' as [WebSiteUrl] UNION SELECT UserId, Company, WebSiteUrl FROM [UserProfile] ORDER BY [Company]">

------------------------
Conversion failed when converting from a character string to uniqueidentifier.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Consultant, Trainer
Commented:
how about this one:
SelectCommand="SELECT '"+Guid.Empty.ToString()+"' as UserId, '' as  [Company], '' as [WebSiteUrl] UNION SELECT UserId, Company, WebSiteUrl  FROM [UserProfile] ORDER BY [Company]"

Author

Commented:
Sorry that not it either...

Author

Commented:
Thanks
Reza RadConsultant, Trainer

Commented:
your welcome,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial