How to Get a Specific Column Value from a DataTable?

前端 未结 6 1919
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 02:08

I have a datatable. I need to fetch a certain column value based on the user input. For example, lets say the datatable has two columns CountryID and CountryName.

I

6条回答
  •  Happy的楠姐
    2020-12-13 02:42

    I suppose you could use a DataView object instead, this would then allow you to take advantage of the RowFilter property as explained here:

    http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx

    private void MakeDataView() 
    {
        DataView view = new DataView();
    
        view.Table = DataSet1.Tables["Countries"];
        view.RowFilter = "CountryName = 'France'";
        view.RowStateFilter = DataViewRowState.ModifiedCurrent;
    
        // Simple-bind to a TextBox control
        Text1.DataBindings.Add("Text", view, "CountryID");
    }
    

提交回复
热议问题