我很难确定这段代码中的具体问题是什么。我是初学者,我还在学习 mysql 和 c#。我该如何解决这个问题?
else
{
int countMemberCat = 0;
helper.openConnection();
string query2 = "SELECT Count (*) as 'NoOfMembershipRate' FROM membershiprate WHERE memberrate_desc = @mdesc";
MySqlCommand cmd2 = new MySqlCommand(query2, helper.getConnection());
cmd2.Parameters.AddWithValue("mdesc", txtMemRateDesc.Text);
MySqlDataReader reader = cmd2.ExecuteReader();
while (reader.Read())
{
countMemberCat = int.Parse(reader["NoOfMembershipRate"].ToString());
}
helper.CloseConnection();
if (countMemberCat > 0)
{
MessageBox.Show("Membership Category already exist!");
}
else
{
try
{
double price = double.Parse(txtMemRate.Text);
ClearErrorMessage();
DialogResult dr = MessageBox.Show("Are you sure you want to add new membership category?", "Add?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
if (helper.openConnection())
{
string query = "INSERT INTO `membershiprate` (`memberrate_desc`, memberrate_id, `memberrate_price`, memberrate_count) VALUES (@mdesc, memberrate_id, @mprice, memberrate_id)";
MySqlCommand cmd = new MySqlCommand(query, helper.getConnection());
cmd.Parameters.AddWithValue("mdesc", txtMemRateDesc.Text);
cmd.Parameters.AddWithValue("mprice", txtMemRate.Text);
cmd.ExecuteNonQuery();
helper.CloseConnection();
this.Close();
MessageBox.Show("Successfully added!");
}
这就是问题开始的地方。它在这里说它有一个未处理的 mysql 异常。
MySql.Data.dll 中出现类型为“MySql.Data.MySqlClient.MySqlException”的未处理异常附加信息:您的 SQL 语法有误;检查与您的 MariaDB 服务器版本对应的手册,了解在第 1 行的“*) 附近使用的正确语法作为‘NoOfMembershipRate’ FROM membershiprate WHERE memberrate_desc =‘Adult’”
忽然笑
相关分类