Input string was not in a correct format.Couldn't store <> in CustStdCode Column. Expected type is [Resolved]

Posted by Sudheep.grandhe under C# on 11/25/2011 | Points: 10 | Views : 32249 | Status : [Member] | Replies : 8
Hi,

in my coding i found this error.can you please help me.
Error:
Input string was not in a correct format.Couldn't store <> in CustStdCode Column. Expected type is Int32.
private void btn_new_Click(object sender, EventArgs e)
{
DataRow newrow=_datatable .NewRow ();
newrow ["custname"]=txt_customername .Text ;
newrow ["custaddress"]=txt_customeraddress .Text ;
newrow ["custcity"]=txt_customercity .Text ;
newrow ["custstate"]=txt_customerstate .Text ;
newrow ["custstdcode"]=txt_stdcode .Text;//error:Input string was not in a correct format.Couldn't store <> in CustStdCode Column. Expected type is Int32.
newrow ["custphoneno"]=txt_phoneno .Text ;
newrow ["custmobileno"]=txt_mobileno .Text ;
_datatable .Rows .Add (newrow );

Best,
Sudheep.



Responses

Posted by: Sksingh on: 11/25/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Try this and check whether work or not
newrow ["custstdcode"]=txt_stdcode.text.Trim() == "" ? 0 : convert.toint32(txt_stdcode.text);


Note :
1. Check the datatype of custstdcode
2. Debug and check the value of txt_stdcode.text



Regards,
Sunil

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/25/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Try
newrow ["custstdcode"]=int.Parse(txt_stdcode .Text)

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it shows the error as :Input string was not in a correct format.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/25/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

That meand your textbox value not an integer value. Enter numbers in the textbox and try.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it is an integer only.in db also i declared as int only .and i tried that

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksingh on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
If CustStdCode Column datatype is int32 then first convert it to INT before assinging any value to column.
Mostly i guess error throws because of NULL or empty value of text box.
Handle empty check during conversion.


Regards,
Sunil

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I am trying with that convert.toint32(txt_stdcode.text).it shows the error as :input string was not in a correct format.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

thanks for replying it's working.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response