Retrieve data from a dataset

I have a dataset that is populated from a stored procedure on sql server. I have a column that allows a set of values ​​to be used. I do not know what these values ​​are. All I know is that they are of type string. I want to extract all individual values ​​from this column.

+3
source share
4 answers

You can use the DataView and set the RowFilter to the desired condition:

var view = new DataView(dataset.Tables["Table"]);
view.RowFilter = "Column = 42";

UPDATE : based on your updated question, you can use LINQ:

var table = dataset.Tables["Table"].AsEnumerable();
var distinctValuesForColumn = 
  table.Select(row => (string)row["Column"]).Distinct();
+2
source

You can simply use the DataTable select method:

DataRow[] extractedRows = 
     yourDataSet.Tables["YourTableName"].Select("YourColumnName = 123");
0

I hope that the instruction below will serve your purpose

ds.Tables["TableName"].DefaultView.ToTable( true, "columnName"); //For Dataset (true means distinct)

OR

   `ds.Tables[0].DefaultView.ToTable( true, "columnName");

// For a dataset where tableindex is 0

OR

dt.DefaultView.ToTable( true, "columnName"); //For Datatable

//Syntax is like Datatable.DefaultView.ToTable( Distinct true/false, "ColumnName");

MSDN: http://msdn.microsoft.com/en-us/library/wec2b2e6.aspx

0
source

Source: https://habr.com/ru/post/1767033/


All Articles