Solved

CAching a dataset

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

20 Experts available now in Live!

Get 1:1 Help Now