C#MySQL查询 [英] c# Mysql query
本文介绍了C#MySQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,所以我似乎无法弄清楚我要执行的查询出了什么问题.
这是我拥有的代码
Okay so I can''t seem to figure out what is wrong with the query I''m trying to do.
Here is the code I have
string name;
name = cbxnames.SelectedValue.ToString();
myConnection.GetConnection();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM users WHERE name= "''+name+''", myConnection.GetConnection());
我需要查询才能真正从我的数据库返回东西的是
What i need the query to look like to actually return somthing from my db is
"SELECT * FROM users WHERE name = ''randomname''"
但是我无法弄清楚如何对字符串进行转义.
But I cannot figure out how to escape the strings to make it do that.
推荐答案
您将引号和双引号都颠倒了
应该是:
you have the quotes and double quote reversed
should be:
MySqlCommand cmd = new MySqlCommand("SELECT * FROM users WHERE name='"+name+"'", myConnection.GetConnection());
这篇关于C#MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文