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

解决方案 »

  1.   

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

  2.   

       /// <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();
            }
        }
      

  3.   

    这个应该分解为两个问题:
       1、连接数据库,把你需要的数据写到DataTable里。
       2、循环DataTable,把数据写入txt        
    要用到的都是很基础的知识,不是很难......
    要注意的是写入txt的格式,可识别、整齐规范                
      

  4.   


    大哥 我知道很基础呀 问题不会呀 怎么做嘞 感觉和ASP差别好大的
      

  5.   

    不要动不动就跪求之类的.
    男儿膝下有黄金,跪天跪地跪父母,其他的任何东西都不值得你跪.你的问题不是我能回答的,因为回答了你也看不懂,就像楼上几楼的代码.
    因你提及:
    "我看先前的项目 完全看不懂 他的连接是手动输进去的"
    你现在需要做的,并不是看这个帖子的答案,而是先去把原来的代码看懂先.
    修改到的相关代码都无法看懂,那这个功能你就不能急急忙忙来CSDN找简单答案.