|
-
May 23rd, 2012, 09:42 AM
#1
Thread Starter
Lively Member
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
-
May 23rd, 2012, 10:13 AM
#2
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.
-
May 24th, 2012, 05:01 AM
#3
Thread Starter
Lively Member
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.
-
May 24th, 2012, 05:08 AM
#4
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.
-
May 24th, 2012, 09:21 AM
#5
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
-
May 24th, 2012, 09:24 AM
#6
Re: inserting 10 digits number from textbox to sql server 2005 error
 Originally Posted by DataMiser
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.
-
May 24th, 2012, 02:53 PM
#7
Thread Starter
Lively Member
Re: inserting 10 digits number from textbox to sql server 2005 error
-
May 25th, 2012, 02:21 AM
#8
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|