OpenFileDialog opfd = new OpenFileDialog();
opfd.ShowDialog();
string lujing = opfd.FileName;
if (lujing != "")
{
StreamReader sr = new StreamReader(new FileStream(lujing, FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
string sLine = "";
ArrayList al = new ArrayList();
string connstr = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
al.Add(sLine);
}
sr.Close();
foreach (string sOutput in al)
{
string[] strs = sOutput.Split('|');
string name = "'" + strs[0] + "'";
string phone1 = "'" + strs[1] + "'";
string phone2 = "'" + strs[2] + "'";
string mail = "'" + strs[3] + "'";
string mobile1 = "'" + strs[4] + "'";
string mobile2 = "'" + strs[5] + "'";
string address = "'" + strs[6] + "'";
string youbian = "'" + strs[7] + "'";
string carcard = "'" + strs[8] + "'";
string chejiahao = "'" + strs[9] + "'";
string chexing = "'" + strs[10] + "'";
string mendian = "'" + strs[11] + "'";
string buydate = "'" + strs[12] + "'";
string suggestion = "'" + strs[13] + "'";
string beizhu = "'" + strs[14] + "'";
string huifang = "'" + strs[15] + "'";
cmd.CommandText = "insert into T_Customer(CustomName,PhoneOne,PhoneTwo,Mail,MobileOne,MobileTwo,Address,Youbian,CarCard,ChejiaNum,chexing,Mendian,BuyDate,Suggestion,Beizhu,IsVisit)values(" + name + "," + phone1 + "," + phone2 + "," + mail + "," + mobile1 + "," + mobile2 + "," + address + "," + youbian + "," + carcard + "," + chejiahao + "," + chexing + "," + mendian + "," + buydate + "," + suggestion + "," + beizhu + "," + huifang + ")";
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("数据导入成功!");
}
else
{
return;
}
opfd.ShowDialog();
string lujing = opfd.FileName;
if (lujing != "")
{
StreamReader sr = new StreamReader(new FileStream(lujing, FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);
string sLine = "";
ArrayList al = new ArrayList();
string connstr = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
al.Add(sLine);
}
sr.Close();
foreach (string sOutput in al)
{
string[] strs = sOutput.Split('|');
string name = "'" + strs[0] + "'";
string phone1 = "'" + strs[1] + "'";
string phone2 = "'" + strs[2] + "'";
string mail = "'" + strs[3] + "'";
string mobile1 = "'" + strs[4] + "'";
string mobile2 = "'" + strs[5] + "'";
string address = "'" + strs[6] + "'";
string youbian = "'" + strs[7] + "'";
string carcard = "'" + strs[8] + "'";
string chejiahao = "'" + strs[9] + "'";
string chexing = "'" + strs[10] + "'";
string mendian = "'" + strs[11] + "'";
string buydate = "'" + strs[12] + "'";
string suggestion = "'" + strs[13] + "'";
string beizhu = "'" + strs[14] + "'";
string huifang = "'" + strs[15] + "'";
cmd.CommandText = "insert into T_Customer(CustomName,PhoneOne,PhoneTwo,Mail,MobileOne,MobileTwo,Address,Youbian,CarCard,ChejiaNum,chexing,Mendian,BuyDate,Suggestion,Beizhu,IsVisit)values(" + name + "," + phone1 + "," + phone2 + "," + mail + "," + mobile1 + "," + mobile2 + "," + address + "," + youbian + "," + carcard + "," + chejiahao + "," + chexing + "," + mendian + "," + buydate + "," + suggestion + "," + beizhu + "," + huifang + ")";
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("数据导入成功!");
}
else
{
return;
}