Sign in to follow this  
Followers 0
Hendrick

solved Visual Studios C# Query Fail

3 posts in this topic

Hi-

Wondering if anyone can help me with this. I have a query that returns results just fine in MSSQL, however when I run it in my code, it returns 0 rows. Here's the query:

SELECT m.Email FROM o.dbo.mem m, o.dbo.roleKey u, o.dbo.role r WHERE r.RoleName = 'Member' AND r.rid = u.rid AND u.uid = m.uid
And in the code:
cmd.CommandText = "SELECT m.Email FROM o.dbo.mem m, o.dbo.roleKey u, o.dbo.role r WHERE r.RoleName = 'Member' AND r.rid = u.rid AND u.uid = m.uid";

cmd.Connection = sqlConnection1;

sqlConnection1.Open();

Object rowsR = cmd.ExecuteNonQuery();

SqlDataReader reader = cmd.ExecuteReader();

sqlConnection1.Close();
rowsR returns -1. Again, the query works when I run it in MSSQL. I tried to re-write it with joins, so here is it rewritten a different way, however this doesn't work either. I had to hard code the role values, so I'd prefer to simply fix the first way.
SELECT m.Email FROM o.dbo.mem M JOIN o.dbo.roleKey U ON M.uid = U.uid WHERE rid = 'Key1' OR rid = 'Key2'

I'm really new to Visual Studios. I used Visual Basic about 6 years ago in High School, and have been thrown into Visual Studios in order for this semester long project. So, I may be over looking something incredibly simple, but I'm learning it as I go along.

I also understand that the database isn't set up in the best way, but it's what I've been given and I can't change the structure at this point.

Any help is GREATLY appreciated.

Thanks!

Edited by Hendrick

Share this post


Link to post
Share on other sites

Well yes, you're calling the ExecuteNonQuery() method. This is designed to execute queries that don't return a result to it won't return a result...

What are you hoping to accomplish here?

1 person likes this

Share this post


Link to post
Share on other sites

That would totally be it. I must have read the little pop-up wrong on Visual Studios when trying to decide which executer to use.

I was pulling my hair out over this one.

Thanks again for your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.