0

I have this part of project, written using MS SQL:

 selectCommand.CommandText = "SELECT * FROM Table1";
        var data_ar = selectCommand.ExecuteReader().Select(r =>
           new
           {
               Value1 = r["Value1"].ToString(),
               Value2 = r["Value2"].ToString(),
           })
           .ToList();

How can i change this code to make it work with MySqlConnection instead of SqlConnection?

Dan
  • 75
  • 1
  • 1
  • 6

1 Answers1

0

For using MySQL like this code you need a nuget package that is used for interacting with MySQL server. I ma using this for 7 years www.nuget.org/packages/MySql.Data/7.0.7-m61

All code will be same, just namespace and classes will be changed. All will come with Prefix "My"

Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
  • So, what should I do after installation of that package? – Dan Apr 23 '17 at 15:17
  • @Dan use Mysql.Data.Client and then start using class like MySQLConnection , MySQLCommand, MySQLDatareader. all will work same as SQL server but with prefix "My" – Anirudha Gupta Apr 23 '17 at 15:18
  • ok, I've used MySql.Data.MySqlClient, but I still have error on selectCommand.ExecuteReader().Select: "MySqlDataReader does not contain a definition for "Select". – Dan Apr 23 '17 at 15:25
  • @Dan yup, many things will be missing in Mysql. for common code refer http://stackoverflow.com/a/4018147/713789 – Anirudha Gupta Apr 23 '17 at 15:37