New row not shown in Access after INSERT

C

CZuhars

Hi,

My .NET application writes to an Access 2003 db through OleDb. I'm
using a stored query in Access to insert a new row. The app's C# code
sample includes:

myCommand.CommandType = CommandType.StoreQuery;
myCommand.CommandText = "InsertName";

myCommand.Parameters.AddWithValue("@FIRST", "First name");
myCommand.Parameters.AddWithValue("@LAST", "Last name");

myCommand.Command.Open();
int rowNum = myCommand.ExecuteNonQuery(); // returns 1 row added
myCommand.Command.Close();

The Access Query - (an Append Query?) is:
INSERT INTO Members ( first_name, last_name )
SELECT [@FIRST] AS Expr1, [@LAST ]AS Expr2;

When the app runs, debug says the query returns a row. But when I
look at the table's data, nothing is there.

Any advice?

Thanks!
 
P

Patrice

Are other changes taken into account ?

The usual problem is a db file with the "always copy" property defined in
the VS.NET project. It causes the runtime db file to be always overwritten
when your launch the application...

(also I thought OleDb was not supporting named parameters ?)
 
C

CZuhars

No other changes are happening. I'm just staring with this project,
and my INSERTS are the first thing I'm starting with.

In researching how to do this, I've been told that you can use the
queries in an Access file like a stored procedure on an SQL Server.
However, the named parameters is another issue in question - Not sure
if you can use them, or if you *can't* use the '@' in front of
parameter names. I'd rather not use just straight SQL commands.


Are other changes taken into account ?

The usual problem is a db file with the "always copy" property defined in
the VS.NET project. It causes the runtime db file to be always overwritten
when your launch the application...

(also I thought OleDb was not supporting named parameters ?)

---
Patrice

My .NET application writes to an Access 2003 db through OleDb. I'm
using a stored query in Access to insert a new row. The app's C# code
sample includes:
myCommand.CommandType = CommandType.StoreQuery;
myCommand.CommandText = "InsertName";
myCommand.Parameters.AddWithValue("@FIRST", "First name");
myCommand.Parameters.AddWithValue("@LAST", "Last name");
myCommand.Command.Open();
int rowNum = myCommand.ExecuteNonQuery(); // returns 1 row added
myCommand.Command.Close();
The Access Query - (an Append Query?) is:
INSERT INTO Members ( first_name, last_name )
SELECT [@FIRST] AS Expr1, [@LAST ]AS Expr2;
When the app runs, debug says the query returns a row. But when I
look at the table's data, nothing is there.
Any advice?
 

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