ID
행을 삭제하고 싶기 때문에 행의 를 호출하고 싶습니다.
내 코드는 다음과 같습니다.
private void DeleteAttachment(string ID)
{
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
connection.Open();
string sql = "DELETE FROM EMP_ATTACHED_DOCUMENTS WHERE mkey= @ID";
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
cmd.Parameters.AddWithValue("@ID", ID);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
}
protected void GrdTraining_DeleteCommand(object sender, Obout.Grid.GridRecordEventArgs e)
{
if (Session["dt10"] != null)
{
dt10 = (DataTable)Session["dt10"];
}
else
{
BindDatatable();
}
DeleteAttachment(ID);
DataRow[] grdTrain = dt10.Select("SR_NO=" + Convert.ToString(e.Record["SR_NO"]));
dt10.Rows.Remove(grdTrain[0]);
AddToViewState("GrdTraining");
}
하지만 행을 삭제할 수 없습니다. 나는 그것을 디버깅하려고 할 때,에서 ID
, 나는 얻고 있었다 _Page
.
오류 메시지 :
nvarchar 데이터 형식을 숫자로 변환하는 동안 오류가 발생했습니다.
동적 ID를 호출하는 방법을 제안하십시오.
귀하의 의견에 따라 다음과 같은 작업을 수행해야한다고 생각합니다.
private void DeleteAttachment(string ID)
{
decimal numericId;
if(!decimal.TryParse(ID, out numericId))
{
// The ID is not a valid decimal determine what to do in that case.
}
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
connection.Open();
string sql = "DELETE FROM EMP_ATTACHED_DOCUMENTS WHERE mkey= @ID";
using (SqlCommand cmd = new SqlCommand(sql, connection))
{
cmd.Parameters.Add("@ID", SqlDbType.Decimal).Value = numericId;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
}
또는 메서드에 대한 ID
인수를 DeleteAttachment
a 로 변경하고 메서드 decimal
외부에서 구문 분석을 수행 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다