Results 1 to 8 of 8

Thread: inserting 10 digits number from textbox to sql server 2005 error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    inserting 10 digits number from textbox to sql server 2005 error

    It try to insert 10 digits number to database sql server through textbox it give me this error.

    Here is the code which i use for validation the textbox

    Code:
    Private Sub contacttxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles contacttxt.KeyPress
            If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And e.KeyChar <> Chr(8) Then
                MessageBox.Show("cannot enter char selection only ")
                e.Handled = True
    
            Else
    
                If contacttxt.Text.Length >= 10 Then
                    If e.KeyChar <> ControlChars.Back Then
                        MsgBox("Only 10 Digit")
                        e.Handled = True
                    End If
                End If
            End If
        End Sub

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,386

    Re: inserting 10 digits number from textbox to sql server 2005 error

    That's telling the textbox to only accept the number keys and the backspace. First, I would take a look at JMc's blog on parameters. But I guess ultimately how are you displaying the data? Did you drag it from your datasources? As of right now it's kinda hard to help you out with just seeing that you want your textbox to only accept numbers.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    Re: inserting 10 digits number from textbox to sql server 2005 error

    As with displaying the data i use datagridview. when i enter only 9 digits it work fine but when i enter upto 10 digits it give me this error.
    The conversion of the varchar value '3242342342' overflowed an int column. Maximum integer value exceeded.
    The statement has been terminated.

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: inserting 10 digits number from textbox to sql server 2005 error

    Change the datatype from INT to BIGINT. I'm asssuming it is int.

    Does not work:

    create table #VBForums (TestIt int)

    insert into #VbForums(TestIt) Values(3242342342)

    drop table #VBForums

    Works:

    create table #VBForums (TestIt bigint)

    insert into #VbForums(TestIt) Values(3242342342)

    drop table #VBForums
    Last edited by TysonLPrice; May 24th, 2012 at 05:11 AM.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: inserting 10 digits number from textbox to sql server 2005 error

    If you are using Int as a data type 10 digits will work if the first number is a 1 and may work if it is a 2, will always fail if the first digit is greater than 2

    This is the max value range for an Int data type
    -2,147,483,648 to 2,147,483,647

  6. #6
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: inserting 10 digits number from textbox to sql server 2005 error

    Quote Originally Posted by DataMiser View Post
    If you are using Int as a data type 10 digits will work if the first number is a 1 and may work if it is a 2, will always fail if the first digit is greater than 2

    This is the max value range for an Int data type
    -2,147,483,648 to 2,147,483,647
    I can't be sure with out seeing the app but I suspect the overflow is on the SQL server datatype. If you run the one I marked as doesn't work you will get the overflow message mentioned.

    oops...maybe that is what you meant.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    Smile Re: inserting 10 digits number from textbox to sql server 2005 error

    thank its working.

  8. #8
    New Member
    Join Date
    May 2012
    Posts
    6

    Re: inserting 10 digits number from textbox to sql server 2005 error

    simplier answer. use datatype double with len 10,0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width