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"));
}
好的UserId是一个smallint列但我想把它作为字符串.
我该如何修改上面的linq?
你不能将int一个字符串强制转换为字符串,但是你可以得到int的字符串表示形式:
dtUsers= dsmyTable .Tables[0].AsEnumerable().
         ToDictionary(row => row.Field<short>("UserId").ToString());
但是,您应该只为显示目的这样做.通常,您需要尽可能长时间地保留int,因为处理int更容易,而不是从字符串到处解析它.