我有这个代码用于将数据输入mysql,但是我发现了一个错误:
" MySql.Data.MySqlClient.MySqlException:'您的SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在' 11/05/2018附近使用正确的语法。'在第1行'"
FILE* filePtr = fopen("vehicle.txt", "r");
while (!feof(filePtr)) /* while not End of File */
{
fscanf(filePtr, "%s%s%s", InputFileArray1[i], InputFileArray2[i], InputFileArray3[i]);
i++; /* increment counter */
} /*end while */
错误出现在代码的这一部分
中 private void Button_Click(object sender, RoutedEventArgs e)
{
string especie = txt1.Text;
string nombre = txt2.Text;
string fechanac = txt3.Text;
string fecharev = txt4.Text;
int numanimales = 0;
int cont = 0;
var dbCon = DBConnection.Instance();
dbCon.DatabaseName = "animalia";
if (dbCon.IsConnect())
{
string query = "SELECT COUNT(*) FROM ANIMALES;";
var cmd = new MySqlCommand(query, dbCon.Connection);
numanimales = Convert.ToInt32(cmd.ExecuteScalar());
}
int id = numanimales + 1;
if (dbCon.IsConnect())
{
if (especie == "" || nombre == "" || fechanac == "" || fecharev == "")
{
MessageBox.Show("Introduzca todos los datos");
}
else
{
cont = 1;
MySqlDataReader reader;
string query = "INSERT INTO ANIMALES VALUES (" + id + ",FALSE,'" + especie + "','" + nombre + "','" + fechanac + "','" + fecharev + "');";
var cmd = new MySqlCommand(query, dbCon.Connection);
reader = cmd.ExecuteReader();
MessageBox.Show("Animal añadido");
reader.Close();
}
if (cont == 1)
{
this.Close();
}
}
}
}
非常感谢那些能帮助我的人。
答案 0 :(得分:0)
您在最后一个属性上缺少结束引号:
...,'" + fecharev + ");";
应该是
...,'" + fecharev + "');";