I'm new in Asp.net and I try to read from a file and store to database the file form is:(the reading is test and it's good)
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();
and when I run the programme I got thsi problem:
The variable name '@idpr' has already been declared. Variable names must be unique
within a query batch or stored procedure.
Could you identify the error I'm lost plz