473,386 Members | 1,741 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,386 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 9577
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.