Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to set row name in textbox from database table using Entity Model But I'm getting this message error "
"Input string was not in a correct format"
" in the query code :

var get = dc.table.Where(b => b.IdRow ==  id).SingleOrDefault();



I'm using "IdRow = key research"


it's not the first time I use this code !
Thank you for you help.

What I have tried:

private void IdRowtextBox_KeyUp(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Enter)
           {

                Entities dc = new Entities();
                int id = Convert.ToInt32(IdRowtextBox.Text) ;

                var get = dc.table.Where(b => b.IdRow ==  id).SingleOrDefault();
                nametextBox.Text = get.name.ToString ();
Posted
Updated 7-Mar-17 0:04am
v3

use Int32.TryParse Method (System)[^]

int id;
           if (int.TryParse(IdRowtextBox.Text.Trim(), out id))
           {
               var get = dc.table.Where(b => b.IdRow == id).SingleOrDefault();
               nametextBox.Text = get.name.ToString();
           }
 
Share this answer
 
Comments
EM_Y 2-Mar-17 4:15am    
Thank you but I'm Still getting same error !
Any other suggestions ?
Karthik_Mahalingam 2-Mar-17 4:16am    
might be from some other place, please point the exact line.
EM_Y 2-Mar-17 4:19am    
Errror shows in this line code :

" var get = dc.table.Where(b => b.IdRow == id).SingleOrDefault();"
Karthik_Mahalingam 2-Mar-17 4:23am    
exact error message pls.
or post a screenshot
EM_Y 2-Mar-17 4:36am    
Error Message Exception "Input string was not in a correct format".
It was a problem in the model entity  , I added a wrong association .
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900