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.
Question
Hendrick
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:
And in the code:
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.
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 HendrickLink to comment
https://www.neowin.net/forum/topic/1135378-visual-studios-c-query-fail/Share on other sites
2 answers to this question
Recommended Posts