DB를 연결하기위한 함수. con = db.GetConnection(); cmd.CommandText = "SP_BoardNotice_Delete"; cmd.Parameters.AddWithValue("@idxNum", idxNum); con.Open(); return returnValue; ExecuteScalar- 실행결과를 returnValue에 반환한다. ExecuteScalar를 사용하기 위해서는 프로시져를 만들 때 쿼리를 실행하고 select를 이용해서 반환값을 만들어줘야한다. 간단하기 위해 나는 대게 프로시져를 만들때 select를 사용하여 반환값을 만들어주지만, ExecuteScalar를 이해하고 있다면 꼭 그럴필요는 없다. ExecuteScalar: 쿼리를 실행하고 쿼리에서 반환된 결과집합의 첫 번째 행의 첫 번째 열을 반환한다. 추가 열이나 행은 무시된다. 프로시져의 반환되는 select 값. ↓
BasicBoardDelete의 ExecuteScalar를 통해 프로시져 실행결과 반환.
↓
BasicBoardDelete를 호출한 페이지로 값 return. SP_BoardNotice_Delete- 프로시져는 다음과 같다. create proc SP_BoardNotice_Delete(@idxNum int) as begin declare @errCode tinyint declare @fileName nvarchar(100) select @fileName = bFile from BoardNotice where idx = @idxNum if(exists(select * from BoardNotice where idx = @idxNum)) select @fileName |
function sendit(obj, pageNum) { var url = "Prog_BoardNotice_Delete.aspx?idxNum=" + obj; var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); if (xmlRequest.ResponseText == 0) { confirm은 괄호안에 원하는 메세지를 띄우고, popup창을 띄울 때 다음과 같이 '확인'과 '취소'를 같이 띄운다. |
public static void FileDelete(string fileName, string defaultPath) { string fullPath = defaultPath + @"\" + fileName; FileInfo fInfo = new FileInfo(fullPath); if (fInfo.Exists) { fInfo.Delete(); } } 파일명과 파일이 저장된 경로만 정확하게 넘어오면 '.Exists'로 파일이 존재하는지 체크. '.Delete'로 파일삭제. |
Prog_BoardNotice_Delete.aspx.cs CommonClass.FileDelete(fileName, defaultPath); Response.Write(0); ▶ 자바스크립트 sendit()로 '0'이 넘어간다. |
<appSettings> <add key="BoardFile" value="~/DataRoom/BoardFile/"/> </appSettings> |
'ASP.NET 기초 게시판 > BasicBoard' 카테고리의 다른 글
BoardWrite.aspx 페이지 & BoardWrite.aspx 자바스크립트 (0) | 2011.03.16 |
---|---|
MSSQL▶ 비밀번호 확인해서 글삭제하기 (0) | 2011.03.14 |
PageNavi_ 게시판 페이징 (6) | 2011.03.10 |
BoardView.aspx 페이지 & BoardView.aspx 자바스크립트 (0) | 2011.02.24 |
MSSQL▶ 테이블 & 글삭제 + 비밀번호비교(확인) 프로시져 (0) | 2011.02.24 |