数据存放在txt文件中,dataGridView1.DataSource = ds.Tables[0].DefaultView; 显示数据,然后把矩阵转化为特定格式:<label> <index1>:<value1> <index2>:<value2> ...SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "文档(*.txt)|*.txt";
StreamWriter output = null;
if (sfd.ShowDialog() == DialogResult.OK)
{
output = new StreamWriter(sfd.FileName);
try
{
if (dt == null)
{
MessageBox.Show("数据集中无数据");
}
else
{ int row = dt.Rows.Count;
int col = dt.Columns.Count; for (int r = 0; r < row; r++)
{
output.Write(dt.Rows[r][0].ToString());
for (int c = 1; c < col; c++)
{
output.Write((c - 1).ToString());
output.Write(":");
output.Write(dt.Rows[r][c].ToString()); }
output.WriteLine();
}
}
output.Close();
}
catch (Exception)
{
MessageBox.Show("Failed save the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}结果和以前的矩阵一样 没有变?C#刚上手,求高手指点?
sfd.Filter = "文档(*.txt)|*.txt";
StreamWriter output = null;
if (sfd.ShowDialog() == DialogResult.OK)
{
output = new StreamWriter(sfd.FileName);
try
{
if (dt == null)
{
MessageBox.Show("数据集中无数据");
}
else
{ int row = dt.Rows.Count;
int col = dt.Columns.Count; for (int r = 0; r < row; r++)
{
output.Write(dt.Rows[r][0].ToString());
for (int c = 1; c < col; c++)
{
output.Write((c - 1).ToString());
output.Write(":");
output.Write(dt.Rows[r][c].ToString()); }
output.WriteLine();
}
}
output.Close();
}
catch (Exception)
{
MessageBox.Show("Failed save the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}结果和以前的矩阵一样 没有变?C#刚上手,求高手指点?
解决方案 »
- 如何提取webBrowser控件定向后页面中的内容?
- C# .net2003 如何根据一个日期获得该周的周四的日期及下周周五的日期
- 用户定义控件问题
- 关于combobox绑定的问题
- C#读WORD内容的问题,请高指高
- datagridview .Rows.Count和它绑定的(datatable) datatable.Rows.Count,两个遍历数据有什么不同?
- 求好用的vb.net 转 c#的工具
- Winform 中如何用在TXT中列数不知道的情况把数据导入数据库呢??
- 数据库中的日期绑定到gridview中只显示年月日
- 有C\C++基础和一点Java基础,学习C#并进而能开发一些小项目,大约要多长时间?(大虾进!)
- 与基础事务管理器的通信失败
- 特殊字符
for (int r = 0; r < row; r++)
{
st=string.Format("<{0}>",dt.Rows[r][0]);
for (int c = 1; c < col; c++)
{
st+=string.Format("<{0}>:<{1}>",c-1,dt.Rows[r][c]);
}
output.WriteLine(st);
}
<498 1.27 0.2298 28.625 26368 588.5 1.3447 92.9063 0.15>
<505 1.26 0.236 29 26416 589.5 1.3467 92.9688 0.14>
....................还是没达到转化格式的目的。
1 1:456 2:88 3:444
45 1:45 2:5456 3:545这种 自己有点琢磨到了 datatable 列设置好像有问题