首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winfrom连接数据取值生成TXT资料

2012-09-10 
winfrom连接数据取值生成TXT文件紧急啊各位大大不会winfrom求教 winfrom怎么连接数据库取值在把放到TXT文

winfrom连接数据取值生成TXT文件
紧急啊 各位大大 不会winfrom 求教 winfrom怎么连接数据库取值在把放到TXT文件中 在生成TXT文件 现在公司要该个项目 我看先前的项目 完全看不懂 他的连接是手动输进去的 我现在在后台自己写一个 要怎么写怎么调用 跪求~~~

[解决办法]
把你的数据写到DataTable里面,然后再写入txt,写入txt方法如下:
FileStream f=new FileStream("1.txt",FileMode.Create);
StreamWriter m=new StreamWriter(f);
m.Write("数据信息");
[解决办法]

C# code
   /// <summary>        /// 写入日志文件        /// </summary>        /// <param name="message">日志内容</param>        public static void CreateFile(string message)        {                       string filepath = Application.StartupPath;            if (!Directory.Exists(filepath + "/ErrorLog"))            {                Directory.CreateDirectory(filepath + "/ErrorLog");            }            if (!File.Exists(filepath + "/ErrorLog/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"))            {                FileStream FsCreate = new FileStream(filepath + "/ErrorLog/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.Create);                FsCreate.Close();            }            FileStream fs = new FileStream(filepath + "/ErrorLog/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.Append);            StreamWriter sw = new StreamWriter(fs);            sw.WriteLine(DateTime.Now.ToString() + "    " + message);            sw.Close();            fs.Close();        }    }
[解决办法]
这个应该分解为两个问题:
1、连接数据库,把你需要的数据写到DataTable里。
2、循环DataTable,把数据写入txt
要用到的都是很基础的知识,不是很难......
要注意的是写入txt的格式,可识别、整齐规范

热点排行