System.Data.SqlClient.SqlException:';靠近';的语法不正确'';c#

System.Data.SqlClient.SqlException:';靠近';的语法不正确'';c#,c#,sql-server,C#,Sql Server,我是StackOverflow的新手,如果我没有正确解释,请提前道歉。 我想从DoctorTbl中删除行,但收到以下消息: '靠近','的语法不正确。' 有人能帮帮我吗 这里我得到了eror:(按以下顺序:DoctorAdapter.Update(dt);) 嗯,您不能使用,逗号运算符在多个列上指定条件。它必须是和或或条件。这正是你得到的错误 WHERE DocFirstName=@DocFirstName,DocLastName=@DocLastName,ExpertiseId=@Expe

我是StackOverflow的新手,如果我没有正确解释,请提前道歉。 我想从DoctorTbl中删除行,但收到以下消息:

'靠近','的语法不正确。'

有人能帮帮我吗


这里我得到了eror:(按以下顺序:DoctorAdapter.Update(dt);)



嗯,您不能使用
逗号运算符在多个列上指定条件。它必须是
条件。这正是你得到的错误

WHERE DocFirstName=@DocFirstName,DocLastName=@DocLastName,ExpertiseId=@ExpertiseId,...
应该是

WHERE DocFirstName=@DocFirstName
AND DocLastName=@DocLastName
AND ExpertiseId=@ExpertiseId
AND License=@License
.......

您的错误是由WHERE子句中的错误语法引起的。在这里,每个条件都应该用AND或or语句链接到下一个条件

但是,要从表中删除记录,只需知道该表的主键,并使用数据中的值搜索数据库中的单个记录。此外,在场景中不需要使用SqlDataAdapter来删除行

因此,假设DoctorID是主键,您可以使用…删除数据库记录

public bool delete(DataRow rowdelete)
{     
    using(SqlCommand cmd = conn.CreateCommand())
    {
        cmd.CommandText = "DELETE FROM DoctorTbl WHERE DoctorID = @doctorid";
        cmd.Parameters.Add("@doctorid", SqlDbType.Int).Value = Convert.ToInt32(rowdelete["DoctorId"]);
        cmd.ExecuteNonQuery();

        // Now fix the in memory table to remove the deleted row 
        DataTable dt = rowDelete.Table;
        rowDelete.Delete();
        table.AcceptChanges();
    }
}

删除一条记录就足以知道该表的主键。DoctorID是主键吗?
WHERE DocFirstName=@DocFirstName
AND DocLastName=@DocLastName
AND ExpertiseId=@ExpertiseId
AND License=@License
.......
public bool delete(DataRow rowdelete)
{     
    using(SqlCommand cmd = conn.CreateCommand())
    {
        cmd.CommandText = "DELETE FROM DoctorTbl WHERE DoctorID = @doctorid";
        cmd.Parameters.Add("@doctorid", SqlDbType.Int).Value = Convert.ToInt32(rowdelete["DoctorId"]);
        cmd.ExecuteNonQuery();

        // Now fix the in memory table to remove the deleted row 
        DataTable dt = rowDelete.Table;
        rowDelete.Delete();
        table.AcceptChanges();
    }
}