Cannot Get Result On ExecuteNonQuery

J

Joe Au

I create a query "GetName" on access as follow:

parameters p_accno text (3), p_accname text(10);
select accname from account where accno=[p_accno];

On Web Form, I have the code

dim acname as string
dim cmd as oledbcommand = new oledbcommand("GetName",oledbconnection1)
cmd.commandtype=commandtype.storedprocedure
cmd.parameter.add(new oledbparameter("paccno",textbox1.text))
cmd.parameter.add(new oledbparameter("paccname",acname))
cmd.parameter.item("paccname").direction=output
cmd.executenonquery()

After that, the acname cannot hold the accname from the database.
Why? Thanks.
 
B

Brendan Reynolds

I don't think Jet supports output parameters. I think you could probably
achieve your goal simply enough, though, by using ExecuteScalar instead of
ExecuteNonQuery.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

Joe Au

Thanks Brendan.

If the query select more than one fields e.g. (select accno,accname,email
from ...), can I use the ExecuteScalar to the results? If not, what should I
do?
Joe


Brendan Reynolds said:
I don't think Jet supports output parameters. I think you could probably
achieve your goal simply enough, though, by using ExecuteScalar instead of
ExecuteNonQuery.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Joe Au said:
I create a query "GetName" on access as follow:

parameters p_accno text (3), p_accname text(10);
select accname from account where accno=[p_accno];

On Web Form, I have the code

dim acname as string
dim cmd as oledbcommand = new oledbcommand("GetName",oledbconnection1)
cmd.commandtype=commandtype.storedprocedure
cmd.parameter.add(new oledbparameter("paccno",textbox1.text))
cmd.parameter.add(new oledbparameter("paccname",acname))
cmd.parameter.item("paccname").direction=output
cmd.executenonquery()

After that, the acname cannot hold the accname from the database.
Why? Thanks.
 
B

Brendan Reynolds

ExecuteReader, I guess.

You might want to ask the question in a .NET newsgroup. While I have done
some work with .NET, I'm not nearly as familiar with it as I am with Access.
The folks in the .NET newsgroups will probably be able to give you more
detailed answers.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Joe Au said:
Thanks Brendan.

If the query select more than one fields e.g. (select accno,accname,email
from ...), can I use the ExecuteScalar to the results? If not, what should I
do?
Joe


Brendan Reynolds said:
I don't think Jet supports output parameters. I think you could probably
achieve your goal simply enough, though, by using ExecuteScalar instead of
ExecuteNonQuery.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


Joe Au said:
I create a query "GetName" on access as follow:

parameters p_accno text (3), p_accname text(10);
select accname from account where accno=[p_accno];

On Web Form, I have the code

dim acname as string
dim cmd as oledbcommand = new oledbcommand("GetName",oledbconnection1)
cmd.commandtype=commandtype.storedprocedure
cmd.parameter.add(new oledbparameter("paccno",textbox1.text))
cmd.parameter.add(new oledbparameter("paccname",acname))
cmd.parameter.item("paccname").direction=output
cmd.executenonquery()

After that, the acname cannot hold the accname from the database.
Why? Thanks.
 

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

Similar Threads


Top