Solved

CAching a dataset

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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