Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting DataView to DataSet

Tags:

c#

asp.net

I have a Dataview that is being populated with 3 rows of data from a stored procedure. I want to put that table in a Dataset. I read, but I may be wrong, is to go from DataView to DataTable To DataSet.

Below is my code. When I hit the if statment, it shows that my DT2.Rows.Count = 3, so it runs DS.Tables.Add(DT2); then throws the following Error. "NullReferenceException was unhandled by user code" Object reference not set to an instance of an object.

I was wondering how does one get a DataView to a Dataset? Thank you for any suggestions.

DataSet DS;
DataView DV = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataTable DT2 = DV.ToTable();

if (DT2 != null & DT2.Rows.Count > 0)
{
       DS.Tables.Add(DT2);
}
like image 211
Zach Avatar asked Mar 18 '23 09:03

Zach


1 Answers

Your DataSet is null. Just initiate it and you should be good to go:

DataSet DS = New DataSet();

The rest of your code is correct.

like image 53
David P Avatar answered Mar 27 '23 17:03

David P