private void btnAction_Click(object sender, RoutedEventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt";
if (ofd.ShowDialog() == false)
{ return; }
string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray();
DateTime startTime = DateTime.Now;
DataTable table = new DataTable();
table.Columns.Add("aa");
table.Columns.Add("bb");
table.Columns.Add("cc");
table.Columns.Add("dd");
for (int i = 1; i < lines.Count(); i++)//过滤掉第一行
{
string line = lines[i];
string[] strs = line.Split('\t');
string startTelNum = strs[0].Trim('"');
string telAera = strs[1].Trim('"');
string telType = strs[2].Trim('"');
string aeraNum = strs[3].Trim('"');
DataRow row = table.NewRow();
row["aa"] = startTelNum;
row["bb"] = telAera;
row["cc"] = telType;
row["dd"] = aeraNum;
table.Rows.Add(row);
}
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connStr))
{
bulkCopy.DestinationTableName = "T_TelNum";
bulkCopy.ColumnMappings.Add("aa", "StartTelNum");
bulkCopy.ColumnMappings.Add("bb", "TelAera");
bulkCopy.ColumnMappings.Add("cc", "TelType");
bulkCopy.ColumnMappings.Add("dd", "AeraNum");
bulkCopy.WriteToServer(table);
}
TimeSpan ts = DateTime.Now - startTime;
MessageBox.Show(ts.ToString() + "秒!");
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。