473,387 Members | 1,542 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,387 software developers and data experts.

ExecuteNonQuery requires a parameter

Hi all,

I'm trying to use the following code in an application:

// retrieve the connection string
string strDbcx = Globals.strDbcx;
// create the connection
OleDbConnection dbcx = new OleDbConnection(strDbcx);
// open the connection
dbcx.Open();

string sqlComplete;

DateTime confirmedDate = DateTime.Now;

sqlComplete = "UPDATE installs SET installConfirmed =
1,installDateConfirmed = confirmedDate WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();

OleDbCommand cmdCompleteInstall = new
OleDbCommand(sqlComplete, dbcx);
cmdCompleteInstall.ExecuteNonQuery();

/*MessageBox.Show(sqlComplete);

OleDbCommand cmdCompleteInstall = new
OleDbCommand(sqlComplete, dbcx);
cmdCompleteInstall.ExecuteNonQuery();*/
dbcx.Close();

however I get the following error:

System.Data.OleDb.OleDbException was unhandled
Message="No value given for one or more required parameters."

The connection string works across the rest of my application, so why
won't it work here?!!

Thanks in advance,

Matt

Jan 9 '07 #1
5 1493
Matt wrote:
Hi all,

I'm trying to use the following code in an application:

// retrieve the connection string
string strDbcx = Globals.strDbcx;
// create the connection
OleDbConnection dbcx = new OleDbConnection(strDbcx);
// open the connection
dbcx.Open();

string sqlComplete;

DateTime confirmedDate = DateTime.Now;

sqlComplete = "UPDATE installs SET installConfirmed =
1,installDateConfirmed = confirmedDate WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();

OleDbCommand cmdCompleteInstall = new
OleDbCommand(sqlComplete, dbcx);
cmdCompleteInstall.ExecuteNonQuery();

/*MessageBox.Show(sqlComplete);

OleDbCommand cmdCompleteInstall = new
OleDbCommand(sqlComplete, dbcx);
cmdCompleteInstall.ExecuteNonQuery();*/
dbcx.Close();

however I get the following error:

System.Data.OleDb.OleDbException was unhandled
Message="No value given for one or more required parameters."

The connection string works across the rest of my application, so why
won't it work here?!!
It's not a problem with the connection string, it's a problem with the
query string - you've misspelled one of your column names.
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Jan 9 '07 #2

Larry Lard wrote:
Matt wrote:
sqlComplete = "UPDATE installs SET installConfirmed =
1,installDateConfirmed = confirmedDate WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();
The connection string works across the rest of my application, so why
won't it work here?!!

It's not a problem with the connection string, it's a problem with the
query string - you've misspelled one of your column names.
Larry,

Thanks for the prompt reply, however I've checked my column names on
both the database and the sql statement and they are the same.

Is there anything else that requires looking at? Is it something really
silly like you can only update one field at a time and I need to run
the update query for each field? I'm going to try that anyway and see
what happens.

Cheers,

Matt

Jan 9 '07 #3
If installDateConfirmed is a required parameter, perhaps this:

DateTime confirmedDate = DateTime.Now;

sqlComplete = "UPDATE installs SET installConfirmed = 1,installDateConfirmed
= " + confirmedDate.ToString() + " WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();
Jan 9 '07 #4
Small addition:

if "installDateConfirmed" column in the database is a DateTime type, not a
text type, you need to use single quote mark in the SQL statement:

sqlComplete = "UPDATE installs SET installConfirmed = 1,installDateConfirmed
= '" + confirmedDate.ToString() + "' WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();
"Raymond Basque" <_NOSPAM_rbasque@_NOSPAM_jednm.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
If installDateConfirmed is a required parameter, perhaps this:

DateTime confirmedDate = DateTime.Now;

sqlComplete = "UPDATE installs SET installConfirmed =
1,installDateConfirmed
= " + confirmedDate.ToString() + " WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();


Jan 9 '07 #5
Norman Yuan <No*****@NotReal.notwrote:
Small addition:

if "installDateConfirmed" column in the database is a DateTime type, not a
text type, you need to use single quote mark in the SQL statement:

sqlComplete = "UPDATE installs SET installConfirmed = 1,installDateConfirmed
= '" + confirmedDate.ToString() + "' WHERE installId = " +
lsbSelectInstallToClose.SelectedValue.ToString();
Or, infinitely preferably, use a parameterised SQL statement in the
first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '07 #6

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

Similar topics

1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
5
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper...
4
by: Rodger Dusatko | last post by:
After entering the sql statement da.deletecommand.commandtext = "Delete from Users where username = @username" I set the parameter to the username I wish to delete. This successfully deletes the...
7
by: RJN | last post by:
Hi I want to get the rerurn value from a stored procedure My stored proc looks like this create proc test ..... if.. return 1
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
0
by: nostradumbass77 | last post by:
Using Enterprise Library 2.0 (Jan 06) and .NET 2.0 (VB.Net 2005) Dim dbPF As Data.Common.DbProviderFactory Try dbPF = Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb") db = New...
5
by: John7000 | last post by:
Hello, I am amateur with VB database usage. I've written a little database that keeps track of names, address, phone numbers etc. It displays the data in a DataGrid and stores them in a...
8
by: roundcrisis | last post by:
Hi all: I m trying to get the return value of a stored procedure with .... DbCommand command = connection.CreateCommand(); command.CommandText = "Exec some_SP"; command.CommandType =...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.