How do I extract data from a DataTable?

前端 未结 7 1603
失恋的感觉
失恋的感觉 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:52

    Please consider using some code like this:

    SqlDataReader reader = command.ExecuteReader();
    int numRows = 0;
    DataTable dt = new DataTable();
    
    dt.Load(reader);
    numRows = dt.Rows.Count;
    
    string attended_type = "";
    
    for (int index = 0; index < numRows; index++)
    {
        attended_type = dt.Rows[indice2]["columnname"].ToString();
    }
    
    reader.Close();
    

提交回复
热议问题