文本T.TEXT内容:
[0]
ID=123
NAME=xxx
AGE=20
[1]
ID=123
NAME=YYY
AGE=30
[2]
ID=123
NAME=ZZZ
AGE=40
[3]
ID=123
NAME=WWW
AGE=40导入字段为id,name,age表t.table 中。
新手分数不多,请大家帮忙,谢谢!

解决方案 »

  1.   


      try
                {
    //文本文档名为:CSDN.txt,放在C盘
    //我修改了一下格式:            //*
                //ID=123,
                //NAME=xxx,
                //AGE=20,
                //*
                //ID=123,
                //NAME=YYY,
                //AGE=30,
                //*
                //ID=123,
                //NAME=ZZZ,
                //AGE=40,
                //*
                //ID=123,
                //NAME=WWW,
                //AGE=40,            System.IO.StreamReader reader = new System.IO.StreamReader(@"C:\CSDN.txt", System.Text.Encoding.Default);
                string s = reader.ReadToEnd();
                s=s.Replace("\r\n","");
                string[] paramString = s.Split('*');
                foreach(string s1 in paramString)
                {
                    if (!string.IsNullOrEmpty(s1))
                    {
                        string[] Sparam = s1.Split(',');
                        int id = int.Parse(Sparam[0].Replace("ID=","")); //此用用substring也可以
                        string name = Sparam[1].Replace("NAME=","");
                        string age = Sparam[2].Replace("AGE=","");
                        string sql = "INSERT INTO t.Table (id,name,age)VALUES('" + id + "','" + name + "','" + age + "')";
                        //下边就是ADO.NET的事了,我就不写了
                    }
                }
                }
                catch
                {
                }