“'='附近的语法不正确。”删除

时间:2019-05-19 13:50:39

标签: wpf data-binding

我有一个问题,我想在数据库中删除,但出现错误:

private int db_execute(string sql_text)
{
        string cn_string = Properties.Settings.Default.Fahrzeug_DatenbankConnectionString;
        SqlConnection cn = new SqlConnection(cn_string);

        if(cn.State != ConnectionState.Open) cn.Open();

        SqlDataAdapter sql_adapt = new SqlDataAdapter(sql_text, cn);
        SqlCommand cmd = new SqlCommand(cn_string,cn);

        int intresult = cmd.ExecuteNonQuery();
        cn.Close();

        return intresult;
}

private void Delete_Loaded_Clicked(object sender, RoutedEventArgs e)
{
    Delet();
}

private void Delet()
{
    Fahrzeug row = mainGrid.SelectedItem as Fahrzeug;

    string FahrzeugName = row.Name.ToString();
    string FahrzeugTyp = row.Typ.ToString();
    int FahrzeugBaujahr = int.Parse(row.Jahr.ToString());

    string sql_text = "DELETE FROM Bericht_Table WHERE Name=" + this.NameEingabe.Text.ToString();
    db_execute(sql_text);

    LadeAusDerDatenbank();
}

这是我得到的错误:

  

System.Data.SqlClient.SqlException:“'='附近的语法不正确

1 个答案:

答案 0 :(得分:0)

我不确定,但是名称周围是否有引号,因此字符串变为有效,即 `“从Bericht_Table中删除,其中Name = \”“ + this.NameEingabe.Text.ToString()+” \“”;