且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从SQL Server表中删除一行

更新时间:2023-02-05 14:16:13

正如您所说的,所有列名都是TEXT类型,因此,有需要通过在IDNumber周围使用单引号来将IDNumber用作文本。..

As you have stated that all column names are of TEXT type, So, there is need to use IDNumber as Text by using single quote around IDNumber.....

    public static void deleteRow(string table, string columnName, string IDNumber)
    {
    try
    {
    using (SqlConnection con = new SqlConnection(Global.connectionString))
    {
         con.Open();
         using (SqlCommand command = new SqlCommand("DELETE FROM " + table + " WHERE " + columnName + " = '" + IDNumber+"'", con))
         {
               command.ExecuteNonQuery();
         }
         con.Close();
    }
    }
    catch (SystemException ex)
       {
       MessageBox.Show(string.Format("An error occurred: {0}", ex.Message));
       }
    }
 }