Related to this question : I'm trying to write an "INSERT" loop : I have got the following query:
CommandText = "INSERT into sample2Prot(timestp,idq,idz,prot,Lhowmany,Rhowmany) VALUES(@timestp,@idq,@idz,@prot,@Lhowmany,@Rhowmany)";
When I execute my code (which can be found just below) I get the following error:
'@timestp' cannot be handle by SqlParameterCollection. ("timestp" = tableNames[0], of string type)
for (int j = 0; j < tableNames.Count; j++)
// tableNames contains the name of the columns, tableTypes the types of the columns
// tableTypes contains
{
if (tableTypes[j] == "INTEGER")
{
myCommand3.Parameters.Add("@" + tableNames[j], System.Data.SqlDbType.Int);
Console.WriteLine("@" + tableNames[j]);
}
else
{
myCommand3.Parameters.Add("@" + tableNames[j], System.Data.SqlDbType.VarChar);
Console.WriteLine("@" + tableNames[j]);
}
}
Console.WriteLine(myCommand3.CommandText);
for (int f = 0; f < total.Count(); f++)
{
for (int k = 0; k < tableNames.Count; k++)
{
myCommand3.Parameters.Clear();
myCommand3.Parameters["@" + tableNames[k]].Value = total[f][k];
}
myCommand3.ExecuteNonQuery();
}
Has someone an idea ? Don't mind asking for more precision.