- private void btnImport_Click(object sender, RoutedEventArgs e)
- {
- string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "文本文件|*.txt";
- if (ofd.ShowDialog() == false)
- {
- return;
- }
- string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray();
- using (SqlConnection conn = new SqlConnection(connStr))
- {
- conn.Open();
- for (int i = 1; i < lines.Length; i++)
- {
- string line = lines[i];
- string[] strs = line.Split('\t');
- string startTelNum = strs[0];
- string city = strs[1].Trim('"');//去掉双引号
- string telType = strs[2].Trim('"');//去掉双引号
- }
- using (SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = @"insert into T_TelNum(StartTelNum,TelType,TelArea)
- values(@StartTelNum,@TelType,@TelArea)";
- cmd.Parameters.Add(new SqlParameter("@StartTelNum",startTelNum));
- cmd.Parameters.Add(new SqlParameter("@TelType", telType));
- cmd.Parameters.Add(new SqlParameter("@TelArea", city));
- }
- }
- }
复制代码 错误1:当前上下文中不存在名称“telType”
错误2:当前上下文中不存在名称“startTelNum”
错误3:当前上下文中不存在名称“city”
|