私はStackOverflowの新機能ですので、事実を正しく説明していない場合は事前にご容赦ください。 DoctorTblから行を削除したいのですが、このメッセージが表示されます:System.Data.SqlClient.SqlException: '不正な構文'、 '。' c#
''、 '。
誰かが私を助けてくれますか?
SqlDataAdapter DoctorAdapter;
DataTable Doctordt;
public DalDoctor()
{
DoctorAdapter = new SqlDataAdapter();
PreperCommands();
}
public DalDoctor(string conn) : base(conn)
{
DoctorAdapter = new SqlDataAdapter();
PreperCommands();
}
private void PreperCommands()
{ //select command
DoctorAdapter.SelectCommand = Conn.CreateCommand();
DoctorAdapter.SelectCommand.CommandText = "SELECT * FROM DoctorTbl";
//delete command
DoctorAdapter.DeleteCommand = Conn.CreateCommand();
DoctorAdapter.DeleteCommand.CommandText = "DELETE FROM DoctorTbl WHERE [email protected],[email protected],[email protected],[email protected],[email protected],[email protected]";
DoctorAdapter.DeleteCommand.Parameters.Add("@DocFirstName", SqlDbType.NChar, 10, "DocFirstName");
DoctorAdapter.DeleteCommand.Parameters.Add("@DocLastName", SqlDbType.NChar, 10, "DocLastName");
DoctorAdapter.DeleteCommand.Parameters.Add("@ExpertiseId", SqlDbType.Int, 10, "ExpertiseId");
DoctorAdapter.DeleteCommand.Parameters.Add("@License", SqlDbType.Int, 10, "License");
DoctorAdapter.DeleteCommand.Parameters.Add("@DocTelephone", SqlDbType.Int, 10, "DocTelephone");
DoctorAdapter.DeleteCommand.Parameters.Add("@DoctorId", SqlDbType.Int, 10, "DoctorId");
}
public bool SaveToDB(DataTable dt)
{
//try
//{
DoctorAdapter.Update(dt);
return true;
//}
//catch (SqlException ex)
//{
// return false;
//}
}
public DataTable FillTable()
{
DataTable dt = new DataTable();
DoctorAdapter.Fill(dt);
dt.TableName = "DoctorTbl";
return dt;
}
public bool delete(DataRow rowdelete)
{
Doctordt = FillTable();
foreach (DataRow dr in Doctordt.Rows)
{
if (Convert.ToInt32(dr["DoctorId"]) == Convert.ToInt32(rowdelete["DoctorId"]))
{
dr.Delete();
}
}
return SaveToDB(Doctordt);
}
ここで私はERORを得る:(この順序で:DoctorAdapter.Update(DT);)
public bool SaveToDB(DataTable dt)
{
try
{
DoctorAdapter.Update(dt);
return true;
}
catch (SqlException ex)
{
return false;
}
}
データベースのレコードを削除することができそのテーブルの主キーを知るには十分です。 DoctorIDは主キーですか? – Steve