Cannot Add Row To Access 2000 DB using insert into command

T

Tom Ashcroft

All

I have the following function

public void AddItem(string cartID, int productID, int quantity)

{

string SQL = "INSERT INTO ShoppingCart ( [CartID], [Quantity],
[ProductID] ) VALUES('" + cartID + "', " + quantity.ToString() + ", " +
productID.ToString() + ")";

try

{

OleDbConnection cn = new OleDbConnection
(ConfigurationSettings.AppSettings["ConnectionString"]);

cn.Open();

OleDbCommand cmd = new OleDbCommand(SQL, cn);

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

cn.Close();

}

catch(Exception e)

{

string err = e.Message;

}

}

when I try to run this code the Exception message is: -

Operation must use an updateable query

If i paste the resulting SQL into the Access 200 query builder and run it,
it works.

If anyone has any idea how to get around this I'd be eternally grateful

cheers

Tom
 
P

Paul Clement

¤ All
¤
¤ I have the following function
¤
¤ public void AddItem(string cartID, int productID, int quantity)
¤
¤ {
¤
¤ string SQL = "INSERT INTO ShoppingCart ( [CartID], [Quantity],
¤ [ProductID] ) VALUES('" + cartID + "', " + quantity.ToString() + ", " +
¤ productID.ToString() + ")";
¤
¤ try
¤
¤ {
¤
¤ OleDbConnection cn = new OleDbConnection
¤ (ConfigurationSettings.AppSettings["ConnectionString"]);
¤
¤ cn.Open();
¤
¤ OleDbCommand cmd = new OleDbCommand(SQL, cn);
¤
¤ cmd.CommandType = CommandType.Text;
¤
¤ cmd.ExecuteNonQuery();
¤
¤ cn.Close();
¤
¤ }
¤
¤ catch(Exception e)
¤
¤ {
¤
¤ string err = e.Message;
¤
¤ }
¤
¤ }
¤
¤ when I try to run this code the Exception message is: -
¤
¤ Operation must use an updateable query
¤
¤ If i paste the resulting SQL into the Access 200 query builder and run it,
¤ it works.
¤
¤ If anyone has any idea how to get around this I'd be eternally grateful

Is this a VB.NET or ASP.NET application? It sounds like it may be a permissions issue.

PRB: Cannot Connect to Access Database from ASP.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;316675&Product=adonet


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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