我在 mysql 数据库中有两个时间字段。我需要在添加新时间之前进行检查,我尝试使用此代码。private bool TimeFound(){ MySqlConnection cnn = new MySqlConnection(DB.GetCS("127.0.0.1", "3306", "db", "root", "password", "utf8")); string query = "SELECT time.From, time.To FROM db.time WHERE " + "(time.From, time.To) NOT IN (SELECT time.From, time.To FROM db.time " + "WHERE (time.From = @From AND time.To = @To"; cnn.Open(); MySqlCommand command = new MySqlCommand(query, cnn); command.Parameters.AddWithValue("@From", dateTimePicker1.Value.ToString("HH:mm:ss")); command.Parameters.AddWithValue("@To", dateTimePicker2.Value.ToString("HH:mm:ss")); object result = command.ExecuteScalar(); if (result == null) { return false; } else { return true; }}每次我尝试调用该函数时,我都会在这一行出错。object result = command.ExecuteScalar();MySql.Data.MySqlClient.MySqlException: '你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行附近使用的正确语法
添加回答
举报
0/150
提交
取消