Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   parameterized sql...dbnull value? (http://www.velocityreviews.com/forums/t301360-parameterized-sql-dbnull-value.html)

darrel 07-03-2006 09:45 PM

parameterized sql...dbnull value?
 
I should know this, but I don't...

How do I enter a null value in an integer field using parameterized SQL?

I have this:

Dim bonding2ID As Integer
If cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString) =
"none" Then
bonding2ID = DBNull.Value
Else
bonding2ID =
cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString)
End If

But it's not liking the 'DBNull.Value' part.

-Darrel

================================================== ===============
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA



Bharathi Kumar 07-04-2006 03:40 AM

Re: parameterized sql...dbnull value?
 
Hi,
I think u r corret.

Try System.DbNull.Value to store a NULL value.


Regards,
Bharti Kumar.


darrel wrote:
> I should know this, but I don't...
>
> How do I enter a null value in an integer field using parameterized SQL?
>
> I have this:
>
> Dim bonding2ID As Integer
> If cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString) =
> "none" Then
> bonding2ID = DBNull.Value
> Else
> bonding2ID =
> cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString)
> End If
>
> But it's not liking the 'DBNull.Value' part.
>
> -Darrel
>
> ================================================== ===============
> Win prizes searching google:
> http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA



Karl Seguin [MVP] 07-04-2006 12:17 PM

Re: parameterized sql...dbnull value?
 
There's no easy way...you can use a nullable type in 2.0, but that only gets
you 1/2 way there anyways.

Write it as a method that returns an object *shrug*

function GetBondId() as object
if BLAH
return DBNull.Value
end if
return cleanSQLinput(BLAHx)
end function

Karl

--
http://www.openmymind.net/



"darrel" <notreal@nowhere.com> wrote in message
news:efGE9nunGHA.2312@TK2MSFTNGP04.phx.gbl...
>I should know this, but I don't...
>
> How do I enter a null value in an integer field using parameterized SQL?
>
> I have this:
>
> Dim bonding2ID As Integer
> If cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString) =
> "none" Then
> bonding2ID = DBNull.Value
> Else
> bonding2ID =
> cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString)
> End If
>
> But it's not liking the 'DBNull.Value' part.
>
> -Darrel
>
> ================================================== ===============
> Win prizes searching google:
> http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
>




Karl Seguin [MVP] 07-04-2006 12:18 PM

Re: parameterized sql...dbnull value?
 
his problem is assigning DBNull.Value to an integer...which you can't.

Karl

--
http://www.openmymind.net/



"Bharathi Kumar" <bharathidotnet@gmail.com> wrote in message
news:1151984411.441988.178080@m79g2000cwm.googlegr oups.com...
> Hi,
> I think u r corret.
>
> Try System.DbNull.Value to store a NULL value.
>
>
> Regards,
> Bharti Kumar.
>
>
> darrel wrote:
>> I should know this, but I don't...
>>
>> How do I enter a null value in an integer field using parameterized SQL?
>>
>> I have this:
>>
>> Dim bonding2ID As Integer
>> If cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString) =
>> "none" Then
>> bonding2ID = DBNull.Value
>> Else
>> bonding2ID =
>> cleanSQLinput(DropDownList_bondingCo2.SelectedItem .Value.ToString)
>> End If
>>
>> But it's not liking the 'DBNull.Value' part.
>>
>> -Darrel
>>
>> ================================================== ===============
>> Win prizes searching google:
>> http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA

>




darrel 07-05-2006 02:42 PM

Re: parameterized sql...dbnull value?
 
> There's no easy way...

Damn.

> function GetBondId() as object
> if BLAH
> return DBNull.Value
> end if
> return cleanSQLinput(BLAHx)
> end function


So, I'm basically just returning two different types of objects? I'll give
that a shot.

Out of curiosity, what kind of object DOES accept null values?

-Darrel



Karl Seguin [MVP] 07-05-2006 04:39 PM

Re: parameterized sql...dbnull value?
 
System.Object is the only one I know about. Even Nullable types in 2.0 don't
natively support a database's NULL value (which makes this pretty useless)

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


"darrel" <notreal@nowhere.com> wrote in message
news:umQwPFEoGHA.4232@TK2MSFTNGP02.phx.gbl...
>> There's no easy way...

>
> Damn.
>
>> function GetBondId() as object
>> if BLAH
>> return DBNull.Value
>> end if
>> return cleanSQLinput(BLAHx)
>> end function

>
> So, I'm basically just returning two different types of objects? I'll give
> that a shot.
>
> Out of curiosity, what kind of object DOES accept null values?
>
> -Darrel
>




prasanth100 09-05-2010 05:12 PM

Re : parameterized sql...dbnull value?
 
Hi,
Try to use DbNull.Value near parameter.It might work

ex :
if(txtName.Text != " ")
{
@Name,SqlDbType.VarChar
}
else
{
@Name,DBNull.Value
}

Try it out and see...


All times are GMT. The time now is 07:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57