How can i iterate through row of particular table associated with SqlDataSource control in VS 2008?

流过昼夜 提交于 2019-12-23 02:42:21

问题


I want to cange the lables in my form according to particular value in rows. I just need how to iterate through table rows.


回答1:


You can use SqlDataSource's Select() method to retrieve data and then you can convert the result into a DataView or a DataReader.

    // Use the result as a DataView.
    var dataview = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    foreach (DataRowView dataviewrow in dataview)
    {
        Label1.Text = dataviewrow["FirstName"].ToString();
    }

    // Use the result as a DataReader.
    var datareader = (SqlDataReader)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
    while (datareader.Read())
    {
        Label2.Text = datareader["LastName"].ToString();

    }
    datareader.Close(); 


来源:https://stackoverflow.com/questions/2384709/how-can-i-iterate-through-row-of-particular-table-associated-with-sqldatasource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!