简体   繁体   English

在C#/ Visual Studio中使用MySql数据库

[英]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. 我的数据库托管在本地主机下的本地MySql服务器上。

I want to know the most flexible and easy way to execute queries on my MySql database (of course in C# code). 我想知道在MySql数据库上执行查询的最灵活,最简单的方法(当然是C#代码)。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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