Reading from MySqlReader
本文关键字:MySqlReader from Reading | 更新日期: 2023-09-27 18:35:40
出于某种原因,我在谷歌中找不到一个好的答案,为什么这段代码dosent工作:
MySqlConnection connection = new MySqlConnection("Databaseyeshuv1");
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText =
"SELECT * FROM `MASADE_FEA_bak2` WHERE `marom_num` equals `3`";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string line = Reader.GetString(1);
this.שטח_קומה_מחושב.Text = line;
}
connection.Close();
这是我得到的错误:
System.ArgumentException:初始化字符串的格式不符合从索引 0 开始的规范。 at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString) at MyApp7.UI.Controls.ShowMASADE_FEA_bak2.KomotMASADE_FEA_bak2TableControlRow.Setשטח_קומ_מחושב()
我认为您在代码中犯了很多错误:
- 字符串
"Databaseyeshuv1"
应该是连接字符串值,而不是名称。您应该编写一些代码以从配置文件中获取该值。看看这里 - 在您的命令文本中,应使用
=
而不是equals
并删除字符引号3
,因此仅使用数字 3。