Solved

CAching a dataset

Posted on 2004-09-29
3
311 Views
Last Modified: 2010-04-23
IAm trying to chache my dataset..however it is giving me this error
Value cannot be null. Parameter name: dataSet

this is my code...

Public Function PopulateDropDownList() As DataTable
        Dim dataAdapter As SqlDataAdapter  ' sqldatasetcommand
        Dim DS As New DataSet
        DS = CType(Cache("BinLocations"), DataSet)
        If DS Is Nothing Then
            Dim oCon As SqlConnection = New SqlConnection(Context.Application("ConnectionString"))
            dataAdapter = New SqlDataAdapter("select strBinLocationName, lngWarehouseBinLocationID from tblWarehouseBinLocations where lngWarehouseID =
          " + warehouseid.ToString + "", oCon)
            dataAdapter.Fill(DS, "tblWarehouseBinLocations")
            Cache.Insert("BinLocations", DS)
        End If
        Return DS.Tables("tblWarehouseBinLocations")
    End Function


code breaks when it comes to this line
dataAdapter.Fill(DS, "tblWarehouseBinLocations")


anyhelp is greatly appreciated
thanks
0
Comment
Question by:yalamanchir
[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
3 Comments
 
LVL 5

Expert Comment

by:tomasX2
ID: 12185631
could it be that in certain cases the warehouseid.ToString is returning an empty string so that when you execute the statement the sql is
select strBinLocationName, lngWarehouseBinLocationID from tblWarehouseBinLocations where lngWarehouseID =  

0
 
LVL 2

Accepted Solution

by:
GohdanTheMoblin earned 500 total points
ID: 12186127
The biggest problem I'm seeing becomes apparent when you snip some of the code out.  I'm going to step through the code with a comment next to each thing:

        Dim DS As New DataSet     'Instantiates the DataSet
        DS = CType(Cache("BinLocations"), DataSet)     'Possibly leaves the DataSet as Nothing
        If DS Is Nothing Then  'Only do this if the DataSet is Nothing
            '<snip>
            dataAdapter.Fill(DS, "tblWarehouseBinLocations") 'DS is Nothing, throw exception


DataAdapter.Fill will not instantiate a new object for DS.  The way you solve this would be to make the following change:

      '<snip>
      If DS Is Nothing Then
            Dim oCon As SqlConnection = New SqlConnection(Context.Application("ConnectionString"))
            DS = New DataSet
            'the rest of your code
0
 

Author Comment

by:yalamanchir
ID: 12189893
thank you gohdon ... it solved my problem
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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