Hi,

I have a web form. On it I am generating a gridview through a stored procedure. Now it has it's DataSource set to dataset object ds.

After generating this gridview. I want to generate an xls file. The code for that is correct. But since I am calling a separate function, dataset object does not exist there. So How to achieve a global daataset object. I tried declaring dataset obj at the top, but wont help !

Structure is somewhat like this:

partial class .....

Dim ds as DataSource = new Datasource()

sub for gridview()

gridview.datasource = ds

end sub

sub GetReport_Click () Handles GetReport.Click

[code for excel sheet]

[here i want to access same ds which has data that went in to gridview...but giving 'Object reference not set to instance of an onject' error]

end sub

End Class

Please help

P.s I tried putting DS object in session and retrieving it. That can be a solution. But what if I have hundreds of rows in my dataset? And if many users are there, wont memory consumption increase ? Can there be another more effiecient way ?

Use Shared modifier to create an application scope object.

public class Test
   public shared ds as New DataSource
End Class

Hi,

I have a web form. On it I am generating a gridview through a stored procedure. Now it has it's DataSource set to dataset object ds.

After generating this gridview. I want to generate an xls file. The code for that is correct. But since I am calling a separate function, dataset object does not exist there. So How to achieve a global daataset object. I tried declaring dataset obj at the top, but wont help !

Structure is somewhat like this:

partial class .....

Dim ds as DataSource = new Datasource()

sub for gridview()

gridview.datasource = ds

end sub

sub GetReport_Click () Handles GetReport.Click

[code for excel sheet]

[here i want to access same ds which has data that went in to gridview...but giving 'Object reference not set to instance of an onject' error]

end sub

End Class

Please help

P.s I tried putting DS object in session and retrieving it. That can be a solution. But what if I have hundreds of rows in my dataset? And if many users are there, wont memory consumption increase ? Can there be another more effiecient way ?

http://forums.asp.net/t/1673067.aspx/1?How+to+make+global+dataset+object

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.