I am trying to insert some data into a sql server 2000 databaseusing c#.net. I am getting the following error message:
SQL Error 8178: Prepared Statement ..... expects @Param1, whichwas not supplied.
Here is the code snippet where all the work takes place:
private void btnSave_Click(object sender, System.EventArgs e)
{
int time = 0;
sqlInsertCommand1.CommandType = CommandType.Text;
sqlInsertCommand1.CommandText = "insert into trainingroomdatavalues(@idnum,@dateof,@timeof,@isa mof,@pur)";
sqlInsertCommand1.Parameters.Add(newSqlParameter(" @idnum",SqlDbType.Int,4));
sqlInsertCommand1.Parameters["@idnum"].Value = 0;
sqlInsertCommand1.Parameters.Add(newSqlParameter(" @dateof",SqlDbType.SmallDateTime,4));
sqlInsertCommand1.Parameters["@dateof"].Value =monthCalendar1.SelectionStart.ToShortDateString() ;
sqlInsertCommand1.Parameters.Add(newSqlParameter(" @timeof",SqlDbType.Int,4));
sqlInsertCommand1.Parameters["@timeof"].Value = 4;
sqlInsertCommand1.Parameters.Add(newSqlParameter(" @isamof",SqlDbType.Bit,1));
sqlInsertCommand1.Parameters["@isamof"].Value = 0;
sqlInsertCommand1.Parameters.Add(newSqlParameter(" @pur",SqlDbType.NVarChar,500));
sqlInsertCommand1.Parameters["@pur"].Value = "to hell withthis";
try{
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
sqlConnection1.Close();
MessageBox.Show("The data was successfully entered into thedatabase","Success",MessageBoxButtons.OK);
}
catch (SqlException ee)
{
foreach(SqlError err in ee.Errors)
{
MessageBox.Show("SQL Error " + err.Number + " : " +err.Message);
}
}
finally
{
sqlConnection1.Close();
}
}
I have added test values for the parameters in order to figureout what was going on, but to no avail. If anyone could pointme in the right directon, I would greatly appreciate it. I havesearched this discussion board, but all the previous suggestionshave not worked! Thanks.
--------------------------------
From: Jonathan Presnell
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>Ngin3RQxo0qexfC53dZ1kg==</Id>