cmd.ExecuteNonQuery();括号附近有语法错误,错在哪里了??
FolderBrowserDialogdlg=newFolderBrowserDialog();if(dlg.ShowDialog()!=DialogResult.OK)...
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() != DialogResult.OK)
{
return;
}
string path = dlg.SelectedPath;
String connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "delete from T_Numbers";
cmd.ExecuteNonQuery();
}
}
string[] files = Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "insert into T_Numbers(StartNo,EndNo,Name) values (@StartNo,@EndNo,@Name)";
foreach (string file in files)
{
string 运营商名称 = Path.GetFileNameWithoutExtension(file);
string[] lines = File.ReadAllLines(file, Encoding.Default);
foreach (string line in lines)
{
string[] strs = line.Split('-');
string 开始号码 = strs[0];
string 结束号码 = strs[1];
string 市 = strs[2];
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("StartNO", 开始号码));
cmd.Parameters.Add(new SqlParameter("EndNO", 结束号码));
cmd.Parameters.Add(new SqlParameter("Name", 运营商名称 + 市));
cmd.ExecuteNonQuery();
}
}
}
}
MessageBox.Show("导入成功"); 展开
if (dlg.ShowDialog() != DialogResult.OK)
{
return;
}
string path = dlg.SelectedPath;
String connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "delete from T_Numbers";
cmd.ExecuteNonQuery();
}
}
string[] files = Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "insert into T_Numbers(StartNo,EndNo,Name) values (@StartNo,@EndNo,@Name)";
foreach (string file in files)
{
string 运营商名称 = Path.GetFileNameWithoutExtension(file);
string[] lines = File.ReadAllLines(file, Encoding.Default);
foreach (string line in lines)
{
string[] strs = line.Split('-');
string 开始号码 = strs[0];
string 结束号码 = strs[1];
string 市 = strs[2];
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("StartNO", 开始号码));
cmd.Parameters.Add(new SqlParameter("EndNO", 结束号码));
cmd.Parameters.Add(new SqlParameter("Name", 运营商名称 + 市));
cmd.ExecuteNonQuery();
}
}
}
}
MessageBox.Show("导入成功"); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询