我在Asp.net新我試着從一個文件中讀取並存儲到數據庫 文件形式:(讀數測試,它是很好的)天冬氨酸插入錯誤
0101;23/05/2014
0602;23/05/2014
0301;23/05/2014
1103;23/05/2014
0201;23/05/2014
1704;23/05/2014
***************
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\user\Desktop\file.txt");
SqlConnection connexion = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=C:\Users\user\Desktop\controle\miniprojet\miniprojet\App_Data\ariche.mdf;Integrated Security=True");
SqlCommand command = connexion.CreateCommand();
String requete = "INSERT INTO commande VALUES(@idpr,@date)";
SqlParameter paramidprod;
SqlParameter paramdate;
connexion.Open();
res.Text="Contents of file.txt = ";
foreach (string line in lines)
{
if (line.Contains('*')) break;
String[] l = line.Split(';');
paramidprod=new SqlParameter("@idpr", line.Substring(0,2));
paramdate = new SqlParameter("@date", l[1]);
command.Parameters.Add(paramidprod);
command.Parameters.Add(paramdate);
command.CommandText = requete;
command.ExecuteNonQuery();
res.Text += "<br>" + l[1] +" "+ line.Substring(0, 2);
}
connexion.Close();
connexion.Dispose();
當我跑我thsi問題的程序:
The variable name '@idpr' has already been declared. Variable names must be unique
within a query batch or stored procedure.
你能確定我迷路了PLZ