2014-01-21 7 views
0

안녕 Demo을 참조하십시오.
나는 내 프로젝트에서 telerik을 사용하고 업 로더를 필요로하지 않고 업로드하고 이미지를 보여줄 수있는 업 로더가 필요하다. 모든 데모 코드를 작성하지만이 작업은 절대로하지 않는다. 임시 테이블에 이미지를 저장하기 때문에 데이터베이스에 문제가있는 것 같다. 데이터베이스 및 show.please에 저장하지 않아도이 이미지를 볼 수 있으며이를 수정하는 데 도움이됩니다.
내 테이블 :버튼없이 사진을 데이터베이스에 업로드하고 AJAX로 즉시 보여줍니다. AsyncUpload

Column Name  Type   Nullable Identity 
-----------  --------  --------- --------- 
ImageID   int    No   Yes 
ImageData  varbinary(MAX) Yes   No 
ImageName  nvarchar(200) Yes   No 
UserID   int    Yes   No 


감사합니다.

답변

0

은 내가 파일 찾아보기 대화 업로드에서 이미지를 선택하려 코드에 문제가 당신이 당신의 데이터베이스에 이미지를 삽입 할 때 그래서 이것은

System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("insert into table(ImageData,ImageName) values (@data,@name)"); 
command.Parameters.AddWithValue("@data", Uploader.fileBytes); 
command.Parameters.AddWithValue("@name", "filename"); 
command.ExecuteNonQuery() 
0

다음과 같은 코드를 확인할 수 있습니다하려고 생각 그것은 내 데이터베이스에 직접.

<telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" MaxFileSize="57971152" 
    DisableChunkUpload="true" HttpHandlerUrl="~/RadAsyncUpload/Handler.ashx" UploadedFilesRendering="BelowFileInput"> 
</telerik:RadAsyncUpload> 

Handler.ashx :

<%@ WebHandler Language="C#" Class="CustomHandler" %> 
using System; 
using System.Web; 
using Telerik.Web.UI; 
public class CustomHandler : AsyncUploadHandler 
{ 
    protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName) 
    { 
     System.IO.Stream fileStream = file.InputStream; 
     byte[] attachmentBytes = new byte[fileStream.Length]; 
     fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length)); 
     System.Data.SqlClient.SqlConnection conn = null; 
     try 
     { 
      try 
      { 
       conn = new System.Data.SqlClient.SqlConnection(
        System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); 
       conn.Open(); 
       System.Data.SqlClient.SqlCommand insertCommand = 
        new System.Data.SqlClient.SqlCommand(
        "Insert into [Pictable] (msgid, pic1) Values (1, @Pic)", conn); 
       insertCommand.Parameters.Add("@Pic", System.Data.SqlDbType.VarBinary).Value = attachmentBytes; 
       int queryResult = insertCommand.ExecuteNonQuery(); 
      } 
      catch (Exception ex) 
      { 
      } 
     } 
     finally 
     { 
      if (conn != null) 
      { 
       fileStream.Close(); 
       conn.Close(); 
      } 
     } 
     return CreateDefaultUploadResult<UploadedFileInfo>(file); 
    } 
} 
+0

덕분에, 내가 데모 같은 구문을해야 할 이유 – user3201543