i want to insert rows one by one into a database in the sql server 2005.
the problem is that i have tried all possible but the rows just dont get added to the database, i get an exception
on executing this code, i get this exception
Unhandled Exception: System.IndexOutOfRangeException: An SqlParameter with ParameterName 'msg' is not contained by this SqlParameterCollection.
here is the code -
SqlConnection thisConnection = new SqlConnection(@"Integrated Security=SSPI;Initial Catalog=sec;Workstation ID=3035-HEADSTRONG;");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
StreamReader sr= new StreamReader(@"e:\fast.txt");
string ss=null;
int i=1;
ss=sr.ReadLine();
Console.WriteLine(ss);
while(ss!=null)
{
i++;
thisCommand.Parameters["msg"].Value=ss;
thisCommand.Parameters["id"].Value=i;
// -----------i have tried this too--------
//thisCommand.CommandText = "INSERT INTO fix (msg,id) VALUES (ss,i)";
//thisCommand.ExecuteNonQuery();
ss=sr.ReadLine();
}