使用“ DELETE FROM”的SQL命令不起作用

时间:2019-05-21 16:06:40

标签: c# sql-server wpf

我试图使用WPF从SQL Server数据库中删除行,但这是行不通的。

我正在构建一个连接到数据库的系统。我做了一些命令,一切正常,但是删除命令不起作用

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyTable"].ConnectionString;

    try
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = ("DELETE FROM [User] WHERE User_Id='" + this.rownum.Text+"'");

        int result = (int)cmd.ExecuteScalar();

        conn.Close();

        if (result > 0)
        {
            MessageBox.Show("Seccessfull Login");
        }
        else
        {
            MessageBox.Show("Incorrect Login");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    finally
    {
        Console.ReadLine();
    }
}

0 个答案:

没有答案