Solved

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

Posted on 2014-12-08
2
23 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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

14 Experts available now in Live!

Get 1:1 Help Now