• txt文本导入到sql server数据库


     protected void Button1_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(new FileStream(@"C:\test.txt", FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);

            SqlConnection cn = new SqlConnection("Server=server0.;uid=sa;pwd=1234;database=ISUZU"); ;

            string insertCmd = "insert into EPSubtute(Escmp,Esoem,Esrelation,Esnew,Espart,Essub) values (@Escmp,@Esoem,@Esrelation,@Esnew,@Espart,@Essub)";
              
            string strTemp = sr.ReadLine();
            while(strTemp != null)
            {           
                SqlCommand cmd =  new SqlCommand(insertCmd, cn);
               
                cmd.Parameters.Add("@Escmp", SqlDbType.VarChar).Value = "ISUZU";
                cmd.Parameters.Add("@Esoem", SqlDbType.VarChar).Value = "IZ";
                cmd.Parameters.Add("@Esrelation", SqlDbType.VarChar).Value =strTemp.Substring(0,2) ;
                cmd.Parameters.Add("@Esnew", SqlDbType.VarChar).Value = strTemp.Substring(2, 10);
                cmd.Parameters.Add("@Espart", SqlDbType.VarChar).Value = strTemp.Substring(12, 10);
                cmd.Parameters.Add("@Essub", SqlDbType.VarChar).Value = strTemp.Substring(22, 1);

                cn.Open();
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch(System.Data.SqlClient.SqlException e1)
                {
                    Console.WriteLine(e1.Message);
                }
                cn.Close();
                strTemp = sr.ReadLine();
            }
            sr.Close();
        }

  • 相关阅读:
    Delete Them
    Toda 2
    JQuery案例:购物车加减
    JQuery案例:折叠菜单
    JQuery案例:暖心小广告
    JQuery案例:左右选
    JQuery动画
    JQuery切换事件
    JQuery文档操作
    JQuery选择器
  • 原文地址:https://www.cnblogs.com/hyd309/p/1328722.html
Copyright © 2020-2023  润新知