Solved

VB Sql

Posted on 2014-09-04
6
128 Views
Last Modified: 2014-09-10
Hi
Hope this is enough information

VB.net
SQL Server 2008

Code -
parameters = new DataParameterCollection
paramerers.add("@test", cStr(Values(2)))

Produces an DBNull to string not valid error
How do I test cStr(Values(2) is Null set the Parameter to ""
or if not Null paramerers.add("@test", cStr(Values(2)))

Thanks
0
Comment
Question by:Kevinfeening
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:NARANTHIRAN
ID: 40305227
Check whether @test returns the value.

Your trying to convert the null value into string that's why it returns  "DBNull to string not valid" error..
0
 

Author Comment

by:Kevinfeening
ID: 40305434
Thanks
as I asked how do I as you commented
Check whether @test returns the value
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40311745
Change

paramerers.add("@test", cStr(Values(2)))

to

If Not String.IsNullOrEmpty(Values(2)) AND Not ISDBNull(Values(2)) Then
    paramerers.add("@test", cStr(Values(2)))
Else
    paramerers.add("@test", "")
End If
0
 

Author Comment

by:Kevinfeening
ID: 40313263
Thanks but it causes errors

On the If Not String.IsNullOrEmpty(Values(2))  Error -
Option strict on disallows implicit conversion from object to string

and Name isdbNull is not declared

Had to Change  Value(2) to cstr(Value(2)) in the first line to remove object to string error and remove the ISDBNull but didn't work

Thanks
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40314065
Ok. Try changing

If Not String.IsNullOrEmpty(Values(2)) AND Not ISDBNull(Values(2)) Then

to

If Not Convert.ISDBNull(Values(2)) Then
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now