Dataset returns null value

Dataset returns null value when it's not supposed to

Page 1 of 1

6 Replies - 4303 Views - Last Post: 01 March 2010 - 03:56 PM Rate Topic: -----

#1 didza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 28-February 10

Dataset returns null value

Posted 01 March 2010 - 03:02 PM

Hi All

I have the following code in my application. When it is executed it brings out a null value at times, where i am sure there should be a value returned. I have checked by running the sql statement in the database and it returns the correct value. What could be wrong with my code? Thanks.

Private Sub GetQtyAlreadyMade()
        Dim ds As New DataSet
        Dim strSQL As String = "Select Sum(QuantityProduced) as QtyProduced from dbo.Historian where JobNo = '" & Trim(strDtgJobNo) & "' AND StockCode = '" & Trim(strDtgStockCode) & "'"
        ds = querySQL(strSQL)
        If Not ds.Tables(0).Rows(0).Item("QtyProduced") Is DBNull.Value Then
            int_Total_Made = ds.Tables(0).Rows(0).Item("QtyProduced")
        Else
            int_Total_Made = 0
        End If
    End Sub



This post has been edited by PsychoCoder: 01 March 2010 - 03:10 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Dataset returns null value

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Dataset returns null value

Posted 01 March 2010 - 03:11 PM

Show us what's in the querySQL method
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Dataset returns null value

Posted 01 March 2010 - 03:22 PM

Also, you might put in a Debug.Print(strSQL) right before the ds= line so that when it produces a null, you can look at the actual statement that is being submitted to make sure there are no anomalies in what you are executing and what you think you are executing.
Was This Post Helpful? 0
  • +
  • -

#4 didza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 28-February 10

Re: Dataset returns null value

Posted 01 March 2010 - 03:32 PM

Hey, This is the rest of the code.

Public Conn As String = "server=SWvr123 ;uid=sa;pwd=LO;database=Gbg"

   Public Function querySQL(ByVal SQL As String) As DataSet

        Try
            openConn()
            Dim da As New SqlDataAdapter(SQL, Conn)
            Dim ds As New DataSet
            da.Fill(ds)
            Return ds
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString)
            Return Nothing
        Finally
            ConPlan.Close()
        End Try

    End Function

Public Sub openConn()

        If ConPlan.State = ConnectionState.Open Then
            ConPlan.Close()
        End If
        ConPlan.ConnectionString = Conn
        ConPlan.Open()

    End Sub



This post has been edited by PsychoCoder: 01 March 2010 - 03:34 PM
Reason for edit:: FRixed code tags, which look like [ code]CODE HERE[/ code], not <code>CODE HERE</code>

Was This Post Helpful? 0
  • +
  • -

#5 ZRonZ  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 206
  • Joined: 09-January 09

Re: Dataset returns null value

Posted 01 March 2010 - 03:42 PM

I had a similar problem in a project. In my project found lower case letters where upper case letters were expected and the letter O where a zero should have been. Put a breakpoint in your else clause and run it until it stops, then check the data with a magnifying glass, so to speak, and see what the data is at that point.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Dataset returns null value

Posted 01 March 2010 - 03:44 PM

Where is the value of strDtgJobNo and strDtgStockCode being set?
Was This Post Helpful? 0
  • +
  • -

#7 didza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 28-February 10

Re: Dataset returns null value

Posted 01 March 2010 - 03:56 PM

strDtgJobNo and strDtgStockCode are coming from a datagrid cell_click


Private Sub dgJobDetails_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgJobDetails.CellClick
        Dim i As Integer

        ResetVars()
        'On Error Resume Next
        i = dgJobDetails.CurrentRow.Index
        [b]strDtgJobNo [/b]= dgJobDetails.Item(0, i).Value
        dDtgStart = dgJobDetails.Item(1, i).Value
        intDtgTimeTake = dgJobDetails.Item(2, i).Value
        intDtgQuantity = dgJobDetails.Item(3, i).Value
       [b] strDtgStockCode [/b]= dgJobDetails.Item(5, i).Value
        strDtgLot = dgJobDetails.Item(8, i).Value
        strDtgWH = dgJobDetails.Item(7, i).Value
        strDtgMillNo = Trim(dgJobDetails.Item(4, i).Value)
        strDtgDesc = dgJobDetails.Item(6, i).Value
        strDtgRef = dgJobDetails.Item(9, i).Value
     
    End Sub



This post has been edited by didza: 02 March 2010 - 12:41 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1