Update Statment what am i doing wrong

I

Ivan Sammut

I have the following code but I cannot get it to work. there is no problem with the database connection.



String sLabel = "Ivan"

oConn.Open();

OleDbCommand oCmd = new OleDbCommand("Update category set category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@code",OleDbType.Integer);

oCmd.Parameters.Add("@label",OleDbType.Char,100);

oCmd.Parameters["@code"].Value = iTag;

oCmd.Parameters["@label"].Value = sLabel;

oCmd.ExecuteNonQuery();



Thanks

Ivan Sammut
 
G

Greg Ewing [MVP]

Ivan, what's the error that you get?

--
Greg Ewing [MVP]
http://www.citidc.com


I have the following code but I cannot get it to work. there is no problem
with the database connection.



String sLabel = "Ivan"

oConn.Open();

OleDbCommand oCmd = new OleDbCommand("Update category set
category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@code",OleDbType.Integer);

oCmd.Parameters.Add("@label",OleDbType.Char,100);

oCmd.Parameters["@code"].Value = iTag;

oCmd.Parameters["@label"].Value = sLabel;

oCmd.ExecuteNonQuery();



Thanks

Ivan Sammut
 
C

Chris R. Timmons

I have the following code but I cannot get it to work. there is
no problem with the database connection.



String sLabel = "Ivan"

oConn.Open();

OleDbCommand oCmd = new OleDbCommand("Update category set
category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@code",OleDbType.Integer);

oCmd.Parameters.Add("@label",OleDbType.Char,100);

oCmd.Parameters["@code"].Value = iTag;

oCmd.Parameters["@label"].Value = sLabel;

oCmd.ExecuteNonQuery();

Ivan,

The order of the parameters added to the Parameters collection must
match the order of the parameters defined in the SQL statement.
Change the order of your "Parameters.Add" statements to match the
order they appear in the UPDATE statement:


OleDbCommand oCmd = new OleDbCommand("Update category set
category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@label",OleDbType.Char,100).Value = sLabel;
oCmd.Parameters.Add("@code",OleDbType.Integer).Value = iTag;

oCmd.ExecuteNonQuery();
 
S

Sammut

Thanks works fine now
Chris R. Timmons said:
I have the following code but I cannot get it to work. there is
no problem with the database connection.



String sLabel = "Ivan"

oConn.Open();

OleDbCommand oCmd = new OleDbCommand("Update category set
category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@code",OleDbType.Integer);

oCmd.Parameters.Add("@label",OleDbType.Char,100);

oCmd.Parameters["@code"].Value = iTag;

oCmd.Parameters["@label"].Value = sLabel;

oCmd.ExecuteNonQuery();

Ivan,

The order of the parameters added to the Parameters collection must
match the order of the parameters defined in the SQL statement.
Change the order of your "Parameters.Add" statements to match the
order they appear in the UPDATE statement:


OleDbCommand oCmd = new OleDbCommand("Update category set
category.desc=@label where category.code=@code",oConn);

oCmd.Parameters.Add("@label",OleDbType.Char,100).Value = sLabel;
oCmd.Parameters.Add("@code",OleDbType.Integer).Value = iTag;

oCmd.ExecuteNonQuery();
 

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