How to iterate through a DataTable

后端 未结 4 1434
死守一世寂寞
死守一世寂寞 2020-11-29 19:51

I need to iterate through a DataTable. I have an column there named ImagePath.

When I am using DataReader I do it this way:

4条回答
  •  遥遥无期
    2020-11-29 20:45

    DataTable dt = new DataTable();
    
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    
    adapter.Fill(dt);
    
    foreach(DataRow row in dt.Rows)
    {
        TextBox1.Text = row["ImagePath"].ToString();
    }
    

    ...assumes the connection is open and the command is set up properly. I also didn't check the syntax, but it should give you the idea.

提交回复
热议问题