如何使用C#访问sql数据库中的多行 [英] how to access multiple rows in sql database using C#

查看:109
本文介绍了如何使用C#访问sql数据库中的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找从sql数据库一个接一个的行.我无法遍历表格的第二行.下面是代码示例.请帮忙.

I am looking to access rows one after the other from sql database. I am unable to traverse through to the second row of the table. Below is the code sample. Please help.

if (dr.HasRows)
                {
                    while (dr.Read())
                    //int i=0, j=0;
                    {

                Src_EpId = dr[0].ToString();
                //textBox13.Text = Src_EpId+"\n";

                Device_ID = dr[1].ToString();
                // textBox1.Text = Device_ID;
                Control_ID = dr[2].ToString();
                Control_Type = dr[3].ToString();
                Current_Value = dr[4].ToString();
                Message_State = dr[5].ToString();
                Change_Value = dr[6].ToString();
                Location = dr[7].ToString();
                Image_Url = dr[8].ToString(); // total columns = 9. rows = 5. How to access row2 column1, row2 column2 etc. individually?

推荐答案



您可以先将数据填充到数据表中,然后再访问所需的行和列.

Hi,

You can fill data to datatables first.After that you can access rows and columns whichever you want.

DataTable dt = new DataTable();
dr.Load(dt);
foreach(DataRow dr in dt.Rows)
{
 dr["columnName"];
 // and other columns you can get
}


这篇关于如何使用C#访问sql数据库中的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆