|
-
Apr 13th, 2013, 12:01 AM
#1
Thread Starter
Fanatic Member
Why Int DataType field is holding the string value without any error
Hi. I have a Table in SQL Server 2005 Standard, in which StID is a Primary Key, set to int DataType. When I insert the data from Front End using VB.Net, so If I insert the String Value deliberately and not the Integer. So.
My question is that why it doesn't give any error, for sending string to DataType Int? Please guide me?
Last edited by ADQUSIT; Apr 13th, 2013 at 06:26 AM.
Reason: Little Modification
-
Apr 13th, 2013, 12:57 AM
#2
Re: Why Int DataType field is holding the string value without any error
There's an internal data type conversion from String to Integer
Try inserting the string value but with letters or special characters and see the result
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Apr 13th, 2013, 03:44 AM
#3
Re: Why Int DataType field is holding the string value without any error
so i insert the String Value
Not really. I think you're saying you build up sql as a string so therefore it's a string you're inserting right? Something like this:-
Code:
sql = "Insert Into MyTable (stID) Values (" & anInteger.ToString & ")"
which looks like you're passing a string in. But what that will produce is something like:-
Code:
Insert into MyTable (stID) Values (10)
you'll notice that the 10 doesn't have quotes in it which means that, in SQL world, it's a number. If you passed in a string you'd have:-
Code:
sql = "Insert Into MyTable (stID) Values ('" & anInteger.ToString & "')"
which would produce
Code:
Insert into MyTable (stID) Values ('10')
Even then, as jggtz said, SQL would simply convert it as long as that's possible.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 13th, 2013, 06:28 AM
#4
Thread Starter
Fanatic Member
Re: Why Int DataType field is holding the string value without any error
@ Jggtz and FunkyDexter
I updated my Question, Post # 1.
I didn't use any such converting in my code. So does it mean that SQL Server does this automatically?
-
Apr 13th, 2013, 03:13 PM
#5
Re: Why Int DataType field is holding the string value without any error
So does it mean that SQL Server does this automatically?
It depends on how you're sending the value. If you build up a sql string and don't wrap it in quotes then, as far as SQL Server is concerned it's already an integer. If you do wrap it in quotes then sql server converts it. IF you use an ADO parameter then VB.Net is automatically converting it (assuming you have option strict off). I can't think of any other scenario to cover. Post some example code and I might be able to give a better explanation.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
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
|