How do I store the content of a dataset in a string varialble?
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
精彩评论