hi,
when i insert a row to the table the error will occur
Conversion failed when converting the varchar value 'System.Web.UI.WebControls.TextBox' to data type int.
i cant understand why it will occur,i insert the data regarding to the correct datatype only,
can anyone help me to resolve the answer.
Thanks
Loading
ShambhuPosted Mar 14, 2011, 7:03 AM
Simply you can pass the textbox parameter to store Procedure as it is. And then u can cast into sp itself. Like this
CREATE TABLE A
(
A VARCHAR(2),
B VARCHAR(3) DEFAULT 'SHA',
C int
)
INSERT INTO A (A, C) VALUES('A', CAST('1' as int))
Specify parameter name instead of '1' value.
Venkatesan JayakanthamPosted Mar 3, 2011, 10:30 AM
All the best.
Cheers,
Venkatesan Prabu .J
Head - www.KaaShivinfotech.com
http://venkattechnicalblog.blogspot.com/
Suthish NairPosted Feb 23, 2011, 2:11 PM
Krithika,
These are basics.
TextBox control always return String value only.
Your DB procedure having datatype int.
You need a datatype conversion, for ex: Convert.ToInt16(TextBox1.Text).
I remember in replying your old post saying, always use Parameterized Queries to avoid these type of issues.
So you are not using it yet.
Felipe RamosPosted Feb 23, 2011, 8:03 AM
What you need to do is see if it is an int with a line like:
int temp = -1;
if (int.TryParse(textbox1.Text, out temp))
{
// It is an int
}
else
{
// Invalid entry
Throw new Exception("Invalid value entered.");
}
Jaganathan BantheswaranPosted Feb 23, 2011, 6:12 AM
Instead of using CONVERT use CAST.
Ex:
CAST(@string as int)