0

I wrote this:

IEnumerable<DataRow> query =
                from user in ObjDT_usuario.AsEnumerable()
                where user.Field<string>("Name").StartsWith(query,true,null)
                select user;

It Works fine.

I want to use a variable:

string ColumnName1 = "Name";
IEnumerable<DataRow> query =
                from user in ObjDT_usuario.AsEnumerable()
                where user.Field<string>(ColumnName1).StartsWith(query,true,null)
                select user;

Can anyone help me?

2
  • 1
    Does this work? What's the problem\error\issue\concern? Commented Jun 11, 2013 at 18:57
  • Thanks for your help. The problem was a unassigned local variable. Sorry! The above code works fine.
    – karmany  
    Commented Jun 11, 2013 at 22:25

1 Answer 1

1

The problem is you're using query twice:

IEnumerable<DataRow> **query** =
                from user in ObjDT_usuario.AsEnumerable()
                where user.Field<string>(ColumnName1).StartsWith(**query**,true,null)
                select user;

If you choose a different variable name you should be fine:

string columnName = "Name";
IEnumerable<DataRow> users =
                from user in ObjDT_usuario.AsEnumerable()
                where user.Field<string>(columnName).StartsWith(query,true,null)
                select user;

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.