May 19, 2012  
   Login  
Forum  
 
ForumForumEnesys RS Data ...Enesys RS Data ...Support - RS Da...Support - RS Da...Problems in LookupId fields.Problems in LookupId fields.
Previous Previous
 
Next Next
New Post
 10/14/2008 9:03 PM
 

Hi.

I'm trying to use a Lookup field in a query. When a run it, i've get an error message like this: "Conversion failed when converting the nvarchar value '17B' to data type int."

Here are the query that i'm working on in Visual Studio:

SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Class' LookupId='TRUE'/><Value Type='Lookup'>" + classID + "</Value></Eq></Where>";

In my database a have a Lookup column wich name is Class. This column have the value 17;#17B, wich represents the ID and the Text of the field. If both of this two parameters are diferent, my query return the error above, if the values are the same, it works very well. Actually, i need to consult this value passing the first parameter, in this case 17, but my query insists to pass the second parameter, 17B.

Thanks.
Regards.

 

New Post
 10/15/2008 9:21 AM
 
 Modified By Marien Monnier  on 10/15/2008 9:22:09 AM

Hi,

If your value is 17;#17B, you should be able to split the value on the separator:

string column = "17;#17B";
string[] values = column.Split(new[] {";#"}, StringSplitOptions
.None);
string columnId = values[0];
// 17
string columnValue = values[1]; // 17B
// then you can do your SPQuery with the columnId

Hope this helps,

Regards,

Marien Monnier
Enesys

New Post
 10/16/2008 4:49 PM
 

Hi Marien.

Thanks for the response.... Actually, i use this statement many times in my code, then i forget to change the parameter LookupId="TRUE" in one of them. Now it's work very well.

Regards.
Angelo Martins.

Previous Previous
 
Next Next
ForumForumEnesys RS Data ...Enesys RS Data ...Support - RS Da...Support - RS Da...Problems in LookupId fields.Problems in LookupId fields.

 
You need to login for posting to the forums.
If you don't have a login, click here to register.
You need to login for posting to the forums.
If you don't have a login, click here to register.
 
Copyright 2010 Enesys - All rights reserved Terms Of UsePrivacy Statement