I get this error here is my code
var query1 = (from cust1 in context2.Clients
where cust1.ID == int.Parse(textBox1.Text)
select cust1).FirstOrDefault();`
even if my ID is an Int not a string
I get this error here is my code
var query1 = (from cust1 in context2.Clients
where cust1.ID == int.Parse(textBox1.Text)
select cust1).FirstOrDefault();`
even if my ID is an Int not a string
Call Parse
method outside of your query:
var id=int.Parse(textBox1.Text);
var result=context2.Clients.FirstOrDefault(cust=> cust.ID ==id );
I imagine the simplest solution would be to convert to an int
before the query:
var id = int.Parse(textBox1.Text);
var query1 = (from cust1 in context2.Clients
where cust1.ID == id
select cust1).FirstOrDefault();
Or, for the sake of error handling:
var id = 0;
if (!int.TryParse(textBox1.Text, out id)) {
// raise an error condition
}
var query1 = (from cust1 in context2.Clients
where cust1.ID == id
select cust1).FirstOrDefault();
You have to set the int.Parse to a variable first, like this:
var intValue = int.Parse(textBox1.Text);
var query1 = (from cust1 in context2.Clients
where cust1.ID == intValue
select cust1).FirstOrDefault();