Groups | Blog | Home
all groups > dotnet ado.net > january 2007 >

dotnet ado.net : New row not shown in Access after INSERT


CZuhars
1/30/2007 6:20:06 PM
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!
CZuhars
1/31/2007 5:00:22 AM
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.


[quoted text, click to view]

Patrice
1/31/2007 11:02:18 AM
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

"CZuhars" <czuhars@gmail.com> a écrit dans le message de news:
1170210006.637573.10270@s48g2000cws.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button