我试图让我的mysql连接字符串从文本框中读取,而不是直接字符串,我想做的是这个
string myConnection = "datasource='" + this.label12 + "';username='" + this.textBox3 + "';password='" + this.textBox4 + "';SSL Mode=Required;Certificate Store Location=CurrentUser;";
我收到错误无法连接到任何 mysql 服务器
用 C# 编码
最佳答案
您尝试直接使用 label12
和 textBox3
,这会隐式调用对象上的 ToString()
,并且通常只返回对象的类型(例如“System.Windows.Controls.Label”)。
使用标签和文本框的Text
属性。 (为了便于阅读,我还使用了 String.Format
。)
var myConnection
= string.Format("datasource='{0}';username='{1}';password='{2}';SSL Mode=Required;Certificate Store Location=CurrentUser;",
label12.Text, textBox3.Text, textBox4.Text);
我不知道您正在构建的连接字符串是否有效。您可能想查看connectionstrings.com sample 。
关于c# - 从文本框中读取的连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24196065/