Solved

CAching a dataset

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

22 Experts available now in Live!

Get 1:1 Help Now