开发者

How do I store the content of a dataset in a string varialble?

开发者 https://www.devze.com 2023-03-13 01:32 出处:网络
I have a dataset ds which contains around 37 k table records, i want to store the 1st one(to see a sample record) in a string variable. How do I do that?

I have a dataset ds which contains around 37 k table records, i want to store the 1st one(to see a sample record) in a string variable. How do I do that?

Thanks, Amrutha 开发者_开发技巧


You could try something like this:

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)


Try string row = ds.Tables[0].Rows[0].ToString()

If you want to display something more custom I'd advise

DataRow row = ds.Tables[0].Rows[0];

string summary = "Field1 = " + row["Field1"] + "; Field2 = "+ row["Field2"]; //etc

I would also ask myself why I have a variable in memory containing 37k rows and if that's the only way to achieve what I need.


I think this is what you're looking for

Dataset Visualizer Dialog Box
http://msdn.microsoft.com/en-us/library/d480bk47.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消