Sign in | Join
Last post 05-11-2008 11:22 PM by Bo Chen – MSFT. 5 replies.
Sort Posts: Oldest to newest Newest to oldest
cmdSQL.Parameters.Add(
When I run the application, I get the following error:
Conversion from string "" to type 'Decimal' is not valid
I can't see where the problem is with this..
Thanks for any help!
I think it's because IIf doesn't shortcut the evaluation, i.e. even when slitwidth = "" it still tries to evaluate CDec(slitwidth) thus throwing the exception. You might have to add another line before to convert slitwidth to Nothing if it's an empty string (though I'm not a VB.Net programmer so there may be a better way of fixing it).
hi,
If slidwidth is amer string like "hello" you cannto convert into it to decimal anyway..even in the case of using norma If statement too.
whats the datatype for slitwidth ?
Cheers mate
vijay
elegantkvc: hi, If slidwidth is amer string like "hello" you cannto convert into it to decimal anyway..even in the case of using norma If statement too. whats the datatype for slitwidth ? Cheers mate vijay
It is a string.
So how can I get the value in the text box to be used as a parameter in a stored procedure. The textbox value is a string right?
if slitwidth value is a decimal value means,you can try
IIF(Not(slitwidth = ""),cdec(slitwidth),System.DBNull.Value)
You cant get the string value as input and compare it using IIf statemtn
IIF(Not(slitwidth = ""),cdec(slitwidth),System.DBNull.Value) or IIF(Not(slitwidth = ""),Convert.ToDecimal(slitwidth),System.DBNull.Value)
provided that slitwidth is a number-based variable. Otherwise you will get an run-time error(object cannot be cast to decimal).