Solved

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

Posted on 2014-12-08
2
32 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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