Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

12 Experts available now in Live!

Get 1:1 Help Now