Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Sql

Posted on 2014-09-04
6
Medium Priority
?
138 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
5 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

782 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