Update Statment what am i doing wrong

  • Thread starter Thread starter Ivan Sammut
  • Start date Start date
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
 
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
 
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();
 
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();
 
Back
Top