Conversion failed when converting from a character string to uniqueidentifier in where clause

I have created the query below. But for some reason, I'm getting Conversion failed when converting from a character string to uniqueidentifier error. If I remove one of the OR statement in the where clause then it is working as expected. Kindly advise if I'm doing anything wrong

SELECT * from tblUsers WHERE (isnull(@ActiveOnly,0) = 0 OR (@ActiveOnly = 1 AND StatusCode <> 'Registered'))

Comments

What datatype is @ActivityOnly and tblUsers.StatusCode?

Which field involved here is a uniqueidentifier field? Then you can answer your question quickly.


1 solution

Solution 1

Kindly try :-

SELECT * from tblUsers WHERE (isnull(@ActiveOnly,0) = 0 OR (convert(int,@ActiveOnly) ) = 1 AND StatusCode <> 'Registered'))

  1. Home
  2. Vb.net
  3. Error In Vbnet Conversion Failed When Converting From A Character String To Uniqueidentifier

Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause
Conversion failed when converting from a character string to uniqueidentifier in where clause

Error in VB.Net -- Conversion failed when converting from a character string to uniqueidentifier

Tags: vb.net , sql-server , uniqueidentifier , datatable Answers: | Viewed 1,803 times

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

I am using a String on the VB side and a GUID on the database side.....

Is there an equivalent field that I can use on the VB side that can work well with a "uniqueidentifier" data type in the Sql Server



Some Code Answers


strSql.Append("INSERT INTO tableName ") strSql.Append("(GUID, ParentObsSetGUID, ChildObsSetGUID, ChildObsItemGUID) ") strSql.Append(String.Format("VALUES (CONVERT(uniqueidentifier, '{0}'), CONVERT(uniqueidentifier, '{1}'), CONVERT(uniqueidentifier, '{2}'), CONVERT(uniqueidentifier, '{3}'))", parmList.ToArray))


parmList.Add(Guid.NewGuid().ToString())


parmList.Add(String.Empty)


parmList.Add(dtNewGUID.Rows(0).Item(0).ToString) parmList.Add(dtResultParentGUID.Rows(0).Item(0).ToString) parmList.Add(dtResultChildGUID.Rows(0).Item(0).ToString) // remove the line with the empty string parameter strSql.Append("INSERT INTO tableName ") strSql.Append("(GUID, ParentObsSetGUID, ChildObsSetGUID, ChildObsItemGUID) ") strSql.Append(String.Format("VALUES (CONVERT(uniqueidentifier, '{0}'), CONVERT(uniqueidentifier, '{1}'), CONVERT(uniqueidentifier, '{2}'), NULL)", parmList.ToArray)) // Note the change to the last line. '{3}' becomes NULL. // Make sure you remove the single quotes


Dealing with error 8169 "Conversion failed when …

1 week ago Feb 12, 2019  · Customer was receiving the following error: Msg 8169, Level 16, State 2, Line 1 Conversion failed when converting from a character string to uniqueidentifier. Here are all the ways that you can recreate this error: use tempdb . go . create table t1 (cuid uniqueidentifier default NEWID(), cint int) create table t2 (cuid_char varchar (20), cint int)

Show details

See also: String

Conversion failed when converting from a character string …

6 days ago Jul 03, 2013  · Conversion failed when converting date and/or time from character string while inserting datetime 516 Pad a string with leading zeros so …

Reviews: 5

Show details

See also: String Date

Conversion failed when converting from a character string …

6 days ago Sep 25, 2009  · Conversion failed when converting from a character string to uniqueidentifier. Created a stored procedure in SQL 9 (2005) and have since upgraded to SQL 10 (2008). Since then, the following stored procedure has stopped working and thrown up the above error: ALTER PROCEDURE [dbo].

Reviews: 2

Show details

See also: String

Conversion failed when converting from a character string …

1 day ago Oct 07, 2021  · Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace ...

Show details

See also: String

Conversion failed when converting from a character string …

3 days ago Aug 08, 2011  · Basically I created 2 tables (one having with nvarchar(100) data type and one having uniqueidentifier data type). When I try to write a query where I am selecting data from table A (with nvarchar(100) field) and in subquery checking it with table B (having uniqueidentifier) I am able to get the results (with same CAST function).

Show details

See also: String Function

Conversion failed when converting from a character string …

1 week ago Apr 23, 2019  · When two data types meet in SQL Server, SQL Server will convert the column with the data type that has lowest precedence to the other type (as far as there is an implicit conversion, that is.) varchar ranks low in that list, so it will be converted to uniqueidentifier which ranks higher.

Show details

See also: String List

"Conversion failed when converting from a character …

6 days ago I solved it by instantiating the userid as an object. Dim userId As Object = Membership.GetUser (User.Identity.Name).ProviderUserKey. i passed the object to the function as a guid. ByVal userId As Guid. Dim dbParam_userId As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter. dbParam_userId.ParameterName = "@UserId".

Show details

See also: Function

Error "Conversion failed when converting from a character string …

1 week ago Jul 14, 2010  · Good day I have SQL server with Cyrillic_General_100_CI_AS collation. On this server I have OperationManagrDW database created by DBCreateWizard. Database collation is SQL_Latin1_General_CP1_CI_AS. When I try to install Reporting component of OpsMgr, got error: Conversion failed when converting ... · If SCSM uses reporting services in any way, …

Show details

See also: Database String

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

3 days ago Feb 20, 2019  · Conversion failed when converting from a character string to uniqueidentifier. Share. Improve this answer. Follow ... Conversion failed when converting date and/or time from character string while inserting datetime sql server ... Conversion failed when converting date or time from character string error? 0. SSRS Rectangle visibility based on ...

Show details

See also: Sql String Date

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

1 week ago Sep 21, 2011  · It doesn't even create requests (it does not create entries in the request log). Thus I don't believe that this is an RCDC problem. One interesting thing is that request log shows that it has deleted ma-data objects. some of those failed but it indeed deleted those as well! I used profiler to see what is really going on and it seems that stored ...

Show details

See also: String Rest File

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

5 days ago Nov 20, 2012  · Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

Show details

See also: String

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

5 days ago Dec 29, 2013  · ALTER PROCEDURE [BDUC].[um_getrideridfromusername] @username VARCHAR(36) AS BEGIN SET NOCOUNT ON; Select r.riderid from riders r join aspnet_Users au ON au.UserId = CAST(r.userid AS uniqueidentifier) WHERE au.UserName = @username END I originally did not do the cast, but adding it made no difference!

Show details

See also: String

Please leave your answer here: