1

如何使用Datarow根据列名检索数据?我正在尝试从我的第一次循环中循环数据库数据

//Trying to get data
DataRow dr = dsResult.Tables[1].Rows[0];
//trying to get data successful 

//what i trying to achieve is to retrieve data from database based on rows index and 
     column name
for(int i =0; i <datagridview.Rows.Count ; i++){

   string a = dr['ColumnName'].['RowsIndex'].toString(); //Failed

}
4

3 回答 3

1
        for (int i = 0; i < dataTable.Rows.Count; i++)
        {
            DataRow dr = dataTable.Rows[i]; //Where the RowIndex
            string a = dr[0].ToString();    //Where the ColumnIndex or ColumnName
        }
于 2013-02-20T02:50:14.597 回答
1

尝试 ?

dr.Rows[RowsIndex]['ColumnName'].ToString()
于 2013-02-20T03:47:56.223 回答
0

您是否尝试过删除'columnName'规范之后的句点,并放置rows[i]["columnName"]而不是[columnName][rows]

于 2013-02-20T02:48:18.960 回答