protected void Button1_Click (object sender, EventArgs e) {System.IO.StreamReader my = new System.IO.Str Eamreader ("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 ("Saved successfully! "); } else {this. Response.Write ("Error! "); } sqlcnn. Close (); }
Guide Package
Using system.data.sqlclient;using system.configuration;
ASP. NET reads txt and imports the database