2 juanzhiai1314 juanzhiai1314 于 2016.05.12 16:02 提问

用StreamWriter将DataTable的数据写入其他服务器

这样写对吗

try
{
string SHcontractTxt = @"H" + System.DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
FileStream fs = new FileStream(@"\10.101.0.10\erpsap\0100\" + SHcontractTxt + CreateRandomNo1().ToString(), FileMode.CreateNew, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.End);

                for (int i = 0; i < dsContract.Tables[0].Columns.Count; i++)
                {
                    string a = dsContract.Tables[0].Rows[0][i].ToString();
                    sw.Write(a.Trim() + "|");
                }
                sw.WriteLine();
                sw.Flush();
                sw.Close();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

1个回答

silehaixianghuirenj
silehaixianghuirenj   2016.10.08 01:17

er将DataTable的数据写入其他服务器
这样写对吗
try
{
string SHcontractTxt = @"H" + System.DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
FileStream fs = new FileStream(@"\10.101.0.10\erpsap\0100\" + SHcontractTxt + CreateRandomNo1().ToString(), FileMode.CreateNew, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.End);
for (int i = 0; i < dsContract.Tables[0].Columns.Count; i++)
{
string a = dsContract.Tables[0].Rows[0][i].ToString();
sw.Write(a.Trim() + "|");
}
sw.WriteLine();
sw.Flush();
sw.Close();
return true;

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!