Solved

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

Posted on 2014-12-08
2
20 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 32

Accepted Solution

by:
it_saige earned 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

15 Experts available now in Live!

Get 1:1 Help Now