0

There are a few similar questions, but none of them seem to answer my problem. In my application I use lots of different SELECT queries and I don't want to write a method for every one, so I'm trying to create a generic one that I can just pass the specific parameters in. This is the specific example that I'm trying to modify: SELECT Statement This is my attempt at generalising it: Generic SELECT Statement I have considered trying to split up columns string by the comma delimiter, using list or arrays, but I can't work out how to solve this issue. The specific bit that I want help with is the line with the error ("cannot convert from 'System.Collections.Generic.List' to 'int'"), but I don't know enough about data readers to fix it...

Any help would be greatly appreciated.

  • SQL != OOP..... – juergen d May 10 '17 at 11:29
  • Obviously. I have a C# application connecting to a MySQL database... – user7991284 May 10 '17 at 11:32
  • The point is either write all those statements in your code or use a DB layer library that translates objects into SQL. But don't start patching things together. It is a very bad idea. – juergen d May 10 '17 at 11:41
  • Sounds like you're trying to roll your own ORM... It's doubtful that this is the best solution to your problem! Why not look at a ready made solution such as [Dapper](https://github.com/StackExchange/Dapper) - a lightweight ORM that drives Stack Overflow - or [Entity Framework](https://msdn.microsoft.com/en-us/library/aa937723(v=vs.113).aspx) ? – beercohol May 10 '17 at 12:03

1 Answers1

0

I have a doubt, why do you need to pass columnNames as array of List<string>. array is not needed what I feel. Try passing just the List or array of string and let me know if it worked...

Abi
  • 283
  • 3
  • 16