Reading DataSet in C#
问题 If we have filled a DataSet using a select query in C#, how can we read the column values? I want to do something like this: string name = DataSetObj.rows[0].columns["name"] What would the correct syntax look like to achieve my goal? 回答1: foreach(var row in DataSetObj.Tables[0].Rows) { Console.WriteLine(row["column_name"]); } 回答2: If you already have a dataset, it's something like this; object value = dataSet.Tables["MyTable"].Rows[index]["MyColumn"] If you are using a DataReader: using