sql中的bcp命令产生出来的 ?then you can use c# to read the file or you csv file , and add a header
or use xml as a intermediate to do that
to redbb(....Dotneter....) : 就是这个问题呀,我也想操作这个文件,你可以给我些提示吗?我使用了System.IO.StreamWriter 没有达到我想要的要求
using (FileStream fs = File.OpenRead(path)) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b,0,b.Length) > 0) { Console.WriteLine(temp.GetString(b)); } }
to redbb(....Dotneter....) : 1.我现在的问题是我已经生成了一个csv文件,现在就是想在这个文件上边加上一个头,也就算是操作CSV文件吧,不知道有没有什么比较好的建议!? 2.你上边的代码我知道,你的代码对我而言,存在一点问题就是我的文件中存在中文字体,采用上述的方法我读出的中文全部为乱码!!!对此你有什么解决之道? 当然了,要感谢你对我的答复,如果你可以帮我,我可以另外开帖感谢你的!!!我最重要的是解决第一个问题,谢谢!!!!!
我给你一个建议,我做过相似的东东........代码入下: System.Text.StringBuilder dataNew=new System.Text.StringBuilder(); dataNew.EnsureCapacity(99999); //写出列名 for (int n=1;n<=tmpFieldName.GetUpperBound(0);n++) { dataNew.Append(lbtExport.Items[n-1].Text + ","); } dataNew.Append("\n"); //写出数据 foreach (DataRow row in TmpTable.Rows) { foreach (DataColumn column in TmpTable.Columns) { if (column.ColumnName.ToUpper()!="ID") { dataNew.Append(row[column].ToString() + ","); } } dataNew.Append("\n"); } dataNew.Append("\n");
to chinese:System.IO.StreamReader a=new System.IO.StreamReader(@"d:\test.txt",System.Text.Encoding.GetEncoding("GB2312")); string b=a.ReadToEnd();
if upper method can't resolve your Question , sendme your solution codes ,I can debug it for you
to redbb(....Dotneter....) :)! thank you very much! I will try the method you told me.........if i failed , I will give my codes to you . I think it's better for me , hehe...Thank you very much!
to liuyong_lll(孤醉) Thank you very much too........... you method is very good , i copy the code you give me to my program , success! however, there is little problem , as you told me!hehe........
加入你想要的东西如
===============
select 我想加入的东东
“你的bcp命令”
我的qq:22443800
use xml as a intermediate to do that
就是这个问题呀,我也想操作这个文件,你可以给我些提示吗?我使用了System.IO.StreamWriter 没有达到我想要的要求
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
System.Text.StringBuilder dataNew=new System.Text.StringBuilder();
dataNew.EnsureCapacity(99999);
//写出列名
for (int n=1;n<=tmpFieldName.GetUpperBound(0);n++)
{
dataNew.Append(lbtExport.Items[n-1].Text + ",");
}
dataNew.Append("\n"); //写出数据
foreach (DataRow row in TmpTable.Rows)
{
foreach (DataColumn column in TmpTable.Columns)
{
if (column.ColumnName.ToUpper()!="ID")
{
dataNew.Append(row[column].ToString() + ",");
}
}
dataNew.Append("\n");
}
dataNew.Append("\n");
string b=a.ReadToEnd();
thank you very much! I will try the method you told me.........if i failed , I will give my codes to you . I think it's better for me , hehe...Thank you very much!
you method is very good , i copy the code you give me to my program , success!
however, there is little problem , as you told me!hehe........