Click here to Skip to main content
15,884,970 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
LINQDataContext db = new LINQDataContext();
ClassRoom cr = new ClassRoom();
cr.IdClassRoom = int.Parse(TxtId.Text);
cr.NameClassRoom = TxtName.Text;
cr.IdEducationGroup = int.Parse(ComboboxEducationGroup.ValueMember.ToString());
cr.MinCapacity = int.Parse(TxtMinCapacity.Text);
cr.MaxCapacity = int.Parse(TxtMaxCapacity.Text);
db.ClassRooms.InsertOnSubmit(cr);
db.SubmitChanges();
Posted
Updated 8-Jul-14 16:04pm
v3
Comments
[no name] 8-Jul-14 18:51pm    
Use int.TryParse instead.
[no name] 8-Jul-14 21:28pm    
On which line it's throwing error. For that textbox you have to check that the inputs char only integer or not... Then make a validation from client side

You can try this

C#
cr.IdClassRoom = int.Parse(String.IsNullOrEmpty(TxtId.Text) ? "0" : TxtId.Text);


It will give you the default value 0 if the Text property is empty.
Do that for all your text boxes.
 
Share this answer
 
int.Parse(TxtId.Text);
This line is probably throwing an error.
If you try and parse a non-integer value into an integer, you will get an error.

To avoid these erros, try and use Int.TryParse[^].
This can confirm if the value is an integer before parsing it into an integer variable.
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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