发布网友 发布时间:2022-05-02 08:26
共4个回答
懂视网 时间:2022-05-02 12:47
protected void Button1_Click(object sender, EventArgs e) { System.IO.StreamReader my = new System.IO.StreamReader("C:/Users/Administrator/Desktop/2.txt", System.Text.Encoding.Default); string line; while ((line = my.ReadLine()) != null) { Response.Write(line + "<br />"); string[] mm = line.Split(‘|‘); Insert(mm); } my.Close(); } private void Insert(string[] mm) { string name = mm[0]; string dianhua = mm[1]; string dizhi = mm[2]; string nianling = mm[3]; string xingbie = mm[4]; string strcon = ConfigurationManager.ConnectionStrings["strcn"].ConnectionString; SqlConnection sqlcnn = new SqlConnection(strcon); SqlCommand sqlcmm = new SqlCommand(); sqlcmm.Connection = sqlcnn; sqlcnn.Open(); sqlcmm.CommandText = "insert into users(name,hao,age,sex,dress) values(@name,@hao,@age,@sex,@dress)"; sqlcmm.Parameters.AddWithValue("@hao",dianhua); sqlcmm.Parameters.AddWithValue("@name", name); sqlcmm.Parameters.AddWithValue("@dress",dizhi); sqlcmm.Parameters.AddWithValue("@age", nianling); sqlcmm.Parameters.AddWithValue("@sex", xingbie); int rest = sqlcmm.ExecuteNonQuery(); if (rest > 0) { this.Response.Write("保存成功!"); } else { this.Response.Write("错误!"); } sqlcnn.Close(); }
导包
using System.Data.SqlClient; using System.Configuration;
asp.net读取txt并导入数据库
标签:with nta cti cut 导入数据库 event insert object txt
热心网友 时间:2022-05-02 09:55
可以用fSO逐行读取热心网友 时间:2022-05-02 11:13
a = "xx.txt"热心网友 时间:2022-05-02 12:48
<%