how to get the int value to the database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?=

    how to get the int value to the database

    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.

    LtcCaseReviewDa ta.DcisIICaseNu mINT= Convert.ToInt32 (txtCaseNumber. Text);

    Can any one give me the solution
  • Norm

    #2
    Re: how to get the int value to the database

    On May 28, 2:04 pm, iHavAQuestion
    <iHavAQuest...@ discussions.mic rosoft.comwrote :
    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.
    >
    LtcCaseReviewDa ta.DcisIICaseNu mINT= 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.T ext <String.Empty then
    LtcCaseReviewDa ta.DcisIICaseNu mINT=
    Convert.ToInt32 (txtCaseNumber. Text)
    Else
    LtcCaseReviewDa ta.DcisIICaseNu mINT= -1 ' (or whatever your
    default value is)
    End If

    Comment

    Working...