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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With