Home > Archive > FoxPro Help and Support > June 2005 > (ADO.NET) ExecuteNonQuery returns always 1









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author (ADO.NET) ExecuteNonQuery returns always 1
Sven Heitmann

2005-06-10, 9:24 am

Hi,

I hope I get some help here.

Cindy was so nice to help me, so I got it to work.
However it is something like a workaround and the original problem
still exists.
This is the situation:

I have a FoxPro Database with the following table:
Table: usergroup
Columns: id (autoincrement) as Integer (4)
name as Char (10)

I have also a Stored Procedure:
FUNCTION UpdateUsergroup (tiId, tcName)
UPDATE usergroup SET name = tcName WHERE id = tiId
RETURN _TALLY && THX to Cindy, now it works with ExecuteScalar
ENDFUNC

My OleDbCommandObject is this:
OleDbCommand _cmdUpdateUsergroup;

_cmdUpdateUsergroup = new OleDbCommand();
_cmdUpdateUsergroup.Connection = _connection;
_cmdUpdateUsergroup.CommandType = CommandType.StoredProcedure;
_cmdUpdateUsergroup.CommandText = "UpdateUsergroup";
_cmdUpdateUsergroup.Parameters.Add("@ID",OleDbType.Integer,4);
_cmdUpdateUsergroup.Parameters.Add("@NAME",OleDbType.Char,10);

And I call it this way:
public void UpdateUsergroup(int id, string name) {
if(name == null) {
throw new ArgumentNullExceptio
n("name");
}
_cmdUpdateUsergroup.Parameters[0].Value = id;
_cmdUpdateUsergroup.Parameters[1].Value = name;
try {
_connection.Open();
int n = Convert. ToInt32(_cmdUpdateUs
ergroup.ExecuteNonQuery());
Console.WriteLine(n);
} catch(Exception e) {
Console.WriteLine(e.Message);
} finally {
_connection.Close();
}
}

The Problem is, ExecuteNonQuery always returns 1 :(

However when I use
int n = Convert. ToInt32(_cmdUpdateUs
ergroup.ExecuteScalar());
combined with the Fix in my Stored Procedure (RETURN _TALLY) I get what
I wanted.

But however ExecuteNonQuery seems to be bugged or whatever... does
anybody know whats wrong with it?
I am using the ExecuteScalar solution now, but I am still interested
why I get problem with ExecuteNonQuery or perhaps an solution for it.

Best regards,
Sven Heitmann

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com