Dictionary<string, DataRow> dtUsers;
using (DataSet dsmyTable = DbConnection.db_Select_Query
("use myDb select * from myTable"))
{
dtUsers= dsmyTable .Tables[0].AsEnumerable().
ToDictionary(row => row.Field<string>("UserId"));
}
Alright UserId is a smallint column
But I want to cast it as string.
How should I modify the above linq ?
You can’t cast an
intto a string, but you can get the string representation of the int:However, you should only do this for display purposes. In general, you’ll want to keep the int for as long as you can, as it is much easier to deal with an int instead of parsing it from a string everywhere.