简体   繁体   中英

Working with MySql database in C#/ Visual Studio

Hello, I'm currently working on a project which contains a part in which you have to simply import data from database in different ways. My database is hosted on a local MySql server under localhost.

I want to know the most flexible and easy way to execute queries on my MySql database (of course in C# code). I've tried using string interpolation ($"" syntax) for modifying text of the query but I think it is not the best way to do this. (its getting very complicated when you want to apply some more complex query)

cmd = new MySqlCommand("SELECT * FROM admin WHERE admin_username=@val1 AND admin_password=@val2", MySqlConn.conn);
cmd.Parameters.AddWithValue("@val1", "admin");
cmd.Parameters.AddWithValue("@val2", "pass");
cmd.Prepare();
MySqlDataReader res = cmd.ExecuteReader();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM