Solved

CAching a dataset

Posted on 2004-09-29
3
310 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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