主要代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
namespace testDataSet
{
public partial class TxtToSQL : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImportData()
{
if (FileUpload1.HasFile)
{
using (FileStream fs = File.OpenRead(FileUpload1.PostedFile.FileName))
{
if (Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower() != ".txt")
{
msg("请选择txt文件!"); return;
}
using (StreamReader sr = new StreamReader(fs,Encoding.Default))//编码要写上,不然插入的是乱码!
{
//