c# - 如何将数据集的内容存储在字符串变量中?

标签 c# dataset

我有一个包含大约 37 k 表记录的数据集 ds,我想将第一个(查看样本记录)存储在一个字符串变量中。我该怎么做?

谢谢, 阿姆鲁沙

最佳答案

你可以尝试这样的事情:

private String DataRowToString(DataRow row, DataColumnCollection columns)
{
   StringBuilder rowStringBuilder = New StringBuilder();
   foreach (DataColumn dc in columns)
   {
      dataRowBuilder.AppendFormat("{0} = {1}", dc.ColumnName, row(dc.Ordinal));
      dataRowBuilder.AppendLine();
   }

   return dataRowBuilder.ToString();
}

String rowString = ConvertDataRowToString(ds.Tables[0].Rows[0], ds.Tables[0].Columns)

关于c# - 如何将数据集的内容存储在字符串变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6342120/

相关文章:

c# - 从 C# 调用时,存储过程不返回记录,但在 SSMS 中工作

c# - 自定义 JSON.net 反序列化为 Dictionary<string, string>

c# - System.Data.DataSet 未完全读取 XML 文件

c# - 找不到程序集

c# - Console.Writeline 对性能的影响

c# - 我如何等待 BackgroundWorker?

python - 从 Xarray 中的 `xr.Dataset` 获取值(点、向量、数组等)? ( python 3)

wcf - 使用 DataContractSerializer 序列化 DataSet 时保留 DataRowState

python - 无法迭代 tf.data.Dataset

r - 在 R 中将每行的数据集拆分为较小的文件