how to get the int value to the database

I

iHavAQuestion

I have a registration from in a aspx page.
I also have a textbox contol which takes the int value to be inserted in the
database.
this control is not mandatory.

When I click on the save button, the error is raised saying that the inout
string is not in a correct format.

LtcCaseReviewData.DcisIICaseNumINT= Convert.ToInt32(txtCaseNumber.Text);

Can any one give me the solution
 
N

Norm

I have a registration from in a aspx page.
I also have a textbox contol which takes the int value to be inserted in the
database.
this control is not mandatory.

When I click on the save button, the error is raised saying that the inout
string is not in a correct format.

LtcCaseReviewData.DcisIICaseNumINT= Convert.ToInt32(txtCaseNumber.Text);

Can any one give me the solution

Convert.ToInt32() does not accept empty string.
So if the textbox is not required and is empty that code will attempt
Convert.ToInt32("") will fail with that error.
Here is the fix: (VB sry)

If txtCaseNumber.Text <> String.Empty then
LtcCaseReviewData.DcisIICaseNumINT=
Convert.ToInt32(txtCaseNumber.Text)
Else
LtcCaseReviewData.DcisIICaseNumINT= -1 ' (or whatever your
default value is)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top