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

x
?
Solved

What is causing the DBNull error in my VB.net application

Posted on 2014-12-08
2
Medium Priority
?
37 Views
Last Modified: 2015-12-17
I have a VB.net application that has been working well. I added an additional function to it and it still works well on my development machine, which uses Windows 7 Enterprise OS.  But when I deploy it to the target machine, Windows Server 2008 R2, I get this error message:  Operator '-' is not defined for type DBNull.  I have attached a screen shot of the message box.  Again, I get this error on theServer 2008 machine, but not on the Windows 7 machine.

To my knowledge, I have not DBNull datatypes defined.  A search using the Find & Replace function in Visual Studio for DBNull comes up empty.

What can be causing this error?  How can I track it down?  How can I eliminate it?

T
DBNull-ErrMsg.docx
0
Comment
Question by:thoecherl
2 Comments
 
LVL 35

Accepted Solution

by:
it_saige earned 2000 total points
ID: 40487205
What does the code for Main_Load in SecretShopper.Main contain?  The error is being generated from there.

-saige-
0
 

Author Comment

by:thoecherl
ID: 40487218
Here is the code:

    Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source = TEESPEECEE;Initial Catalog = HLDY;Persist Security Info= True;User ID=sa;Password=123!")
        'Dim cn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source = HOCSQL;Initial Catalog = HLDY;Persist Security Info= True;User ID=sa;Password=Great Plains!")
        Dim strUser = Environment.UserName
        Dim intSecurity, intSS, intHrs, intAmtScore, intProfit, intLoss, intMonthly, intAnnual, intPRDates As Integer

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand
        cmd.CommandType = CommandType.Text
        cmd.Connection = cn
        cmd.CommandTimeout = 0
        cn.Open()

        cmd.CommandText = "SELECT SECURITY FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intSecurity = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT SS FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intSS = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT STOREHRS FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intHrs = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT AMTSCORE FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intAmtScore = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT PROFIT FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intProfit = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT LOSS FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intLoss = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT MONTHLY FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intMonthly = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT ANNUAL FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intAnnual = -cmd.ExecuteScalar()

        cmd.CommandText = "SELECT PRDATES FROM PCT_HOL_SECURITY WHERE USERID = '" & strUser & "'"
        intPRDates = -cmd.ExecuteScalar()

        If intSecurity = 1 Then btnSecurity.Enabled = True
        If intSS = 1 Then btnSS.Enabled = True
        If intHrs = 1 Then btnStoreHrs.Enabled = True
        If intAmtScore = 1 Then btnAmtScore.Enabled = True
        If intProfit = 1 Then btnCStoreProfit.Enabled = True
        If intLoss = 1 Then btnCStoreLoss.Enabled = True
        If intMonthly = 1 Then btnMonthly.Enabled = True
        If intAnnual = 1 Then btnAnnual.Enabled = True
        'If intPRDates = 1 Then btnPRDates.Enabled = True

    End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

877 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