如何使用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
}
答案 0 :(得分: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
}
答案 1 :(得分:1)
试试?
dr.Rows[RowsIndex]['ColumnName'].ToString()
答案 2 :(得分:0)
您是否尝试删除'columnName'
规范后的句点,并放置rows[i]["columnName"]
而不是[columnName][rows]
?