2016-06-02 2 views
1

데이터 열 중 하나로 저장된 이미지 파일로 SQL에 저장된 레코드가 있습니다.화면에서 새 데이터베이스 레코드로 이미지를 저장하는 방법

레코드의 "닫기 복사본"(하나 또는 두 개의 필드 내용을 변경하지만 나머지는 그대로 유지하는 데 사용되는 양식)에서 사용자가 볼 수있는 이미지를 표시하고 있습니다.

어떻게이 이미지 컨트롤의 내용을 새 데이터베이스 레코드에 저장할 수 있습니까? 이미지 파일 내용 대신 int 값 0을 저장해야하는 것을 제외하고는 저장이 작동합니다.

검색어 저장 :

protected void ButtonUpload_Click(object sender, EventArgs e) 
    { 
     string vAuthor = (CloneRecord.FindControl("txt_author") as TextBox).Text; 
     string vDate = (CloneRecord.FindControl("txtDate") as TextBox).Text; 
     string vStem = (CloneRecord.FindControl("txt_stem") as TextBox).Text; 
     string vRespA = (CloneRecord.FindControl("txt_RespA") as TextBox).Text; 
     string vRespB = (CloneRecord.FindControl("txt_RespB") as TextBox).Text; 
     string vRespC = (CloneRecord.FindControl("txt_RespC") as TextBox).Text; 
     string vRespD = (CloneRecord.FindControl("txt_RespD") as TextBox).Text; 
     string vRespE = (CloneRecord.FindControl("txt_RespE") as TextBox).Text; 
     string vAnswer = (CloneRecord.FindControl("txt_Answer") as DropDownList).SelectedValue; 
     string vCritique = (CloneRecord.FindControl("txt_Critique") as TextBox).Text; 
     string vKeyLO = (CloneRecord.FindControl("txt_KeyObjective") as TextBox).Text; 
     string vReference = (CloneRecord.FindControl("txt_References") as TextBox).Text; 
     int vPractice1 = Convert.ToInt32((CloneRecord.FindControl("DDPractice1") as DropDownList).SelectedValue); 
     int vPractice2 = Convert.ToInt32((CloneRecord.FindControl("DDPractice2") as DropDownList).SelectedValue); 
     int vPractice3 = Convert.ToInt32((CloneRecord.FindControl("DDPractice3") as DropDownList).SelectedValue); 
     int vPractice4 = Convert.ToInt32((CloneRecord.FindControl("DDPractice4") as DropDownList).SelectedValue); 
     string vImage1 = (CloneRecord.FindControl("Image1Content") as TextBox).Text; 
     string vImage2 = (CloneRecord.FindControl("Image2Content") as TextBox).Text; 
     string vImage3 = (CloneRecord.FindControl("Image3Content") as TextBox).Text; 
     string vImage4 = (CloneRecord.FindControl("Image4Content") as TextBox).Text; 
     string vIName1 = (CloneRecord.FindControl("Image1Name") as TextBox).Text; 
     string vIName2 = (CloneRecord.FindControl("Image2Name") as TextBox).Text; 
     string vIName3 = (CloneRecord.FindControl("Image3Name") as TextBox).Text; 
     string vIName4 = (CloneRecord.FindControl("Image4Name") as TextBox).Text; 
     string vQuestionID = (CloneRecord.FindControl("IsCloneOf") as TextBox).Text; 
     int vImageFile1 = 0; 
     int vImageFile2 = 0; 
     int vImageFile3 = 0; 
     int vImageFile4 = 0; 

     { 
      string constr = ConfigurationManager.ConnectionStrings["CS1"].ConnectionString; 
      using (SqlConnection con = new SqlConnection(constr)) 
      { 
       string query = "insert into Questions values (@Author, @ImageFile, @Image1Content, @Image1Name, @ImageFile2, @Image2Content, @Image2Name, @ImageFile3, @Image3Content, @Image3Name, @ImageFile4, @Image4Content, @Image4Name,@SubmitDate, @Stem, @RespA, @RespB, @RespC, @RespD, @RespE, @Answer, @Critique, @KeyObjective, @Reference, @PracticeArea1, @PracticeArea2, @PracticeArea3, @PracticeArea4, @IsCloneOf)"; 
       using (SqlCommand cmd = new SqlCommand(query)) 

답변

0

당신은 저장할 수는 이미지 및 문서와 같은 구조화되지 않은 데이터를 저장하기 위해 만들어진 것입니다 BLOB (Binary Large Object)과 같다.

+0

질문은 지금보고있는 웹 페이지에서 이미지를 가져 와서이 쿼리로 만든 새 SQL 레코드에 이미지를 저장하는 방법입니다. 이미 이미지를 저장하는 테이블 구조가 있습니다. 이미지는 원래 "상위"레코드가 생성 될 때 업로드됩니다. –

관련 문제