473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C# Insert Command Parameter Error Message

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>
Jul 21 '05 #1
1 9568
Somewhere else on that form, I bet you'll find a Parameters.Add @Param1.
Looks like maybe sqlInsertCommand1 was built by the configuration wizard and
has already added some params. You could loop through the collection and
see if it exists, I'm betting it does.

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"Jonathan Presnell via .NET 247" <an*******@dotnet247.com> wrote in message
news:eh**************@TK2MSFTNGP12.phx.gbl...
I am trying to insert some data into a sql server 2000 database using
c#.net. I am getting the following error message:
SQL Error 8178: Prepared Statement ..... expects @Param1, which was 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 trainingroomdata
values(@idnum,@dateof,@timeof,@isamof,@pur)";
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@idnum",SqlDbType.Int,4));
sqlInsertCommand1.Parameters["@idnum"].Value = 0;
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@dateof",SqlDbType.SmallDateTime,4)) ;
sqlInsertCommand1.Parameters["@dateof"].Value =
monthCalendar1.SelectionStart.ToShortDateString();
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@timeof",SqlDbType.Int,4));
sqlInsertCommand1.Parameters["@timeof"].Value = 4;
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@isamof",SqlDbType.Bit,1));
sqlInsertCommand1.Parameters["@isamof"].Value = 0;
sqlInsertCommand1.Parameters.Add(new
SqlParameter("@pur",SqlDbType.NVarChar,500));
sqlInsertCommand1.Parameters["@pur"].Value = "to hell with this";

try{
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
sqlConnection1.Close();

MessageBox.Show("The data was successfully entered into the
database","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 figure out what was
going on, but to no avail. If anyone could point me in the right directon,
I would greatly appreciate it. I have searched this discussion board, but
all the previous suggestions have not worked! Thanks.
--------------------------------
From: Jonathan Presnell

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Ngin3RQxo0qexfC53dZ1kg==</Id>
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jason | last post by:
I am picking up an error message on a straightforward INSERT - do I need an optimistic-type to get this working....here is is the error: Microsoft JET Database Engine error '80004005' Operation...
7
by: Bill Kellaway | last post by:
Hi there - this should be fairly simple for someone. Basically I can't figure out how to pass the parameters from ASP to a Stored Procedure on SQL. Here's my code: I just need to help in...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
1
by: Ed Dror | last post by:
Hi there, I have ASP <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Guestbook.aspx.vb" Inherits="Guestbook" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
7
by: Kevin Lawrence | last post by:
Hi all I want to do "INSERT INTO Table (Blob) Values('blobdataasstring')". ...rather than using the parameter driven method, is it possible? And if so what encoder do I use to convert the...
0
by: Rob Dob | last post by:
How do I create a insert command that will take a datatable or datarow as a parameter instead of me having to supply it with parameters for each field value. I heard something about using the v2.0...
8
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal =...
0
by: Michael | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
0
by: bgreer5050 | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.