Solved

VB Sql

Posted on 2014-09-04
6
130 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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