Kelly Martens
asked on
Return schema of query but no data
The user provides my vb.net code with a SQL query that would look like this for example:
select DISTINCT *from employees a INNER JOIN orders b on b.[Employee ID] = a.ID
I want to find a way to populate the datatable I create in code with the query columns and information but not actually get data. Is there a way to do this? The code also accepts queries from MySQL, MS Access, CSV as well as SQL.
select DISTINCT *from employees a INNER JOIN orders b on b.[Employee ID] = a.ID
I want to find a way to populate the datatable I create in code with the query columns and information but not actually get data. Is there a way to do this? The code also accepts queries from MySQL, MS Access, CSV as well as SQL.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can't you just replace * with TOP 0 *
So then SELECT * FROM table becomes SELECT TOP 0 * FROM table and SELECT DISTINCT * FROM table becomes SELECT DISTINCT TOP 0 * FROM table
You would need to cater for other data providers, but this would work for SQL. Perhaps I'm shooting from the hip too much here.
So then SELECT * FROM table becomes SELECT TOP 0 * FROM table and SELECT DISTINCT * FROM table becomes SELECT DISTINCT TOP 0 * FROM table
You would need to cater for other data providers, but this would work for SQL. Perhaps I'm shooting from the hip too much here.
have you tried tools such as Entity Framework or Dapper before? it may help...
Entity Framework
https://msdn.microsoft.com/en-us/library/ee712906(v=vs.113).aspx
Dapper
https://github.com/StackExchange/Dapper
Entity Framework
https://msdn.microsoft.com/en-us/library/ee712906(v=vs.113).aspx
Dapper
https://github.com/StackExchange/Dapper
ASKER
Hey Ryan... I am somewhat handcuffed to do this in the existing code and am unable to rewrite how the application gets it data at this point.
I will never be sure of what query the user will enter. The solution by Dirk would absolutely work if every statement fed into it used *FROM or in my solution if every statement entered never used a DISTINCT like keyword. I THINK I can append LIMIT 1 at the end of any MySQL query. Access and CSV only accepts TOP 1 but appears to work like the TOP in SQL.
I will never be sure of what query the user will enter. The solution by Dirk would absolutely work if every statement fed into it used *FROM or in my solution if every statement entered never used a DISTINCT like keyword. I THINK I can append LIMIT 1 at the end of any MySQL query. Access and CSV only accepts TOP 1 but appears to work like the TOP in SQL.
ASKER
using the reader was the ticket to what I am looking for. Made something complicated that didn't need to be.
ASKER
Thank you Dirk.....
ASKER
I tried parsing the statement and replacing "SELECT" with "SELECT TOP 0" but then somebody threw in a "DISTINCT" keyword and messed that solution up.