Solved

VB Sql

Posted on 2014-09-04
6
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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