load2.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:2k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Text;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Data.SqlClient;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.IO;
- public partial class web_Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- StreamReader sr = new StreamReader(new FileStream(FileUpload1.PostedFile.FileName, FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
- SqlConnection cn = new SqlConnection("Server=127.0.0.1;uid=sa;pwd=123456;database=oa1"); ;
- string insertCmd = "insert into oa_kaoqin(card_id,data,card_time,status) values (@card_id, @data, @card_time,0)";
- char delimChar = ',';
- string split1 = null;
- string split2 = null;
- string split3 = null;
- string strTemp = sr.ReadLine();
- while (strTemp != null)
- {
- split1 = strTemp.Substring(0,10);
- split2 = strTemp.Substring(10, 4) +"-"+ strTemp.Substring(14, 2) +"-"+ strTemp.Substring(16, 2);
- split3 = strTemp.Substring(18,6);
- SqlCommand cmd = new SqlCommand(insertCmd, cn);
- cmd.Parameters.Add("@card_id", SqlDbType.NVarChar).Value = split1;
- cmd.Parameters.Add("@data", SqlDbType.VarChar).Value = split2;
- cmd.Parameters.Add("@card_time", SqlDbType.Decimal).Value = split3;
- cn.Open();
- try
- {
- cmd.ExecuteNonQuery();
- }
- catch (System.Data.SqlClient.SqlException e1)
- {
- Console.WriteLine(e1.Message);
- }
- cn.Close();
- strTemp = sr.ReadLine();
- }
- sr.Close();
- Response.Write("<script> alert('更新成功!')</script>");
- }
- }