简体   繁体   中英

specified cast is not valid in linq to sql

I used this code:

int i = Int32.Parse(dataGridView2.Rows[rowID].Cells["ProfID"].Value.ToString());
var db = new bouDataDataContext();
var sel = db.Payments.Where(c => c.WTID == wtID && c.ProfID == i).Single();

and c.WTID is defined as integer in the database but I receive this error:

specified Cast is not a valid

i think it's because you are doing

c.ProfID == i

where c.ProfID is a string, and i is an integer, if not then

var sel = db.Payments.Where(c => c.WTID == (int)wtID && c.ProfID == i).Single();

should work, that is, if wtID can be casted to integer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM