How do I loop through rows with a data reader in C#?

后端 未结 8 590
孤街浪徒
孤街浪徒 2020-11-30 06:29

I know I can use while(dr.Read()){...} but that loops every field on my table, I want to retrieve all the values from the first row, and then second... and so o

8条回答
  •  感动是毒
    2020-11-30 06:44

    Or you can try to access the columns directly by name:

    while(dr.Read())
    {
        string col1 = (string)dr["Value1"];
        string col2 = (string)dr["Value2"];
        string col3 = (string)dr["Value3"];
    }
    

提交回复
热议问题