How do I extract data from a DataTable?

前端 未结 7 1606
失恋的感觉
失恋的感觉 2020-12-02 07:08

I have a DataTable that is filled in from an SQL query to a local database, but I don\'t know how to extract data from it. Main method (in test program):

<
7条回答
  •  感动是毒
    2020-12-02 07:53

    The DataTable has a collection .Rows of DataRow elements.

    Each DataRow corresponds to one row in your database, and contains a collection of columns.

    In order to access a single value, do something like this:

     foreach(DataRow row in YourDataTable.Rows)
     { 
         string name = row["name"].ToString();
         string description = row["description"].ToString();
         string icoFileName = row["iconFile"].ToString();
         string installScript = row["installScript"].ToString();
     }
    

提交回复
热议问题