获取数据行的值转换成字符串? [英] Getting datarow values into a string?

查看:109
本文介绍了获取数据行的值转换成字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为结果与几行数据集。我想获得这些数据转换为字符串,但我不能完全弄清楚如何做到这一点。我使用的是下面的code:

I have a dataset called "results" with several rows of data. I'd like to get this data into a string, but I can't quite figure out how to do it. I'm using the below code:

string output = "";
foreach (DataRow rows in results.Tables[0].Rows)     
{
    output = output + rows.ToString() + "\n";
}

不过,我想我失去了一些东西,因为这是行不通的。有人能指出我朝着正确的方向?

However, I think I'm missing something because this isn't working. Can someone point me in the right direction?

谢谢!

推荐答案

您需要指定要从中提取数据该数据行的列。

You need to specify which column of the datarow you want to pull data from.

请尝试以下操作:

        StringBuilder output = new StringBuilder();
        foreach (DataRow rows in results.Tables[0].Rows)
        {
            foreach (DataColumn col in results.Tables[0].Columns)
            {
                output.AppendFormat("{0} ", rows[col]);
            }

            output.AppendLine();
        }

这篇关于获取数据行的值转换成字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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