LINQ - is this bug in linq to sql - Asked By bhanupratap singh on 27-Jun-12 02:59 AM

Error is:----String must be exactly one character long.

How to solve it ?

 con = new SqlConnection(Constr);
        SqlCommand cmd = new SqlCommand("select *from Consignment", con);
        
        cmd.CommandType = CommandType.Text;
 HGCNEWDataContext db = new HGCNEWDataContext();
        var cnmtt = from p in db.CONSIGNMENTs
                    where p.GOODS=="R M GOODS"
                    orderby p.CNMT descending 
                  select p;
        GridView1.DataSource = cnmtt;
        GridView1.DataBind();
Jitendra Faye replied to bhanupratap singh on 27-Jun-12 03:12 AM
Refer these links-

http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/42f2d74e-df06-44f4-b644-9c11a1dfd7b6/

Here you will get same issue.
bhanupratap singh replied to S K on 27-Jun-12 03:25 AM
how to solve it I m using studio 2008 and sql 2008
Pls write solution of it
Chintan Vaghela replied to bhanupratap singh on 27-Jun-12 04:19 AM

Hi Frndz,

 

Functionality:  LINQ to SQL Varchar(1) Character Filter

 

 

To achieve this task,

 

In you db table there is filed is Varchar(1) or nVarchar(1)

 

When you drag and Drop you table into DBML file then this type convert to char

 

So there is two way to solved this problem

 

First Way

 

Change varchar(1) filed type char to string in DBML

 

Or

 

 

 

Second Way

 

Set p.GOODS.ToString()

 

 

 

var cnmtt = from p in db.CONSIGNMENTs

              where p.GOODS.ToString() == "R M GOODS"

              orderby p.CNMT descending

              select p;

 

 

 

 

Hope this helpful!

Thanks

 

 

 

bhanupratap singh replied to Chintan Vaghela on 27-Jun-12 07:30 AM
this is still showing same problems
[)ia6l0 iii replied to bhanupratap singh on 27-Jun-12 09:26 PM
Couple of changes:

a)Add a where clause,
SqlCommand cmd = new SqlCommand("select *from Consignment where goods is not null", con);
 

b) If your underlying table has a collation defined, you might have to remove it.

c) Any elements that are mapped to Char(1) can be changed to string. Do this in your designer, recompile and check. 

This is the best shot I can take.