ExecuteNonQuery requires a parameter

M

Matt

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
 
L

Larry Lard

Matt said:
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.
 
M

Matt

Larry said:
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
 
R

Raymond Basque

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();
 
N

Norman Yuan

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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top