2009-07-27 11 views

答えて

11

ただ、パラメータの型としてバイナリを指定し、それは価値がbyte[]

byte[] data; // wherever this comes from 

using (SqlCommand command = new SqlCommand()) 
{ 
    command.Connection = connection; 
    command.CommandText = "INSERT INTO BinaryTable (BinaryData) VALUES (@BinaryData)"; 

    SqlParameter param = new SqlParameter("@BinaryData", SqlDbType.Binary); 
    param.Value = data; 

    command.Parameters.Add(param); 
    command.ExecuteNonQuery(); 
} 

を編集することができます:はまた、注目すべきは、SQL Server 2005/2008を使用している場合は、その代わりにVARBINARY(MAX)を使用するべきであるということです後者は償却されているので、IMAGEです。ここで

0

はサンプル関数の下

public bool AddCompanyIcon(string MakeName, byte[] BytesOriginal,string ImageName) 
    { 
     try 
     { 
      System.Data.SqlClient.SqlParameter[] ImgPara = new SqlParameter[3]; 
      ImgPara[0] = new SqlParameter("@MakeName", MakeName); 
      ImgPara[1] = new SqlParameter("@MakeIcon", BytesOriginal); 
      ImgPara[2] = new SqlParameter("@ImageName", ImageName); 

      db.ExecuteScalerSP("sp_AddAutoCompanyLogo", ImgPara); 
      db.CloseConnection(); 
      return true; 
     } 
     catch 
     { 
      return false; 
     } 
    } 

が、これは...

を助ける sp_AddAutoCompanyLogoストアドプロシージャ

ALTER PROCEDURE [dbo].[sp_AddAutoCompanyLogo] 
    -- Add the parameters for the stored procedure here 
    @MakeName varchar(50), 
    @MakeIcon image, 
    @ImageName varchar(50) 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 
    -- Insert statements for procedure here 
    insert into IVAutoGalleryLogos(MakeName,MakeIcon,ImageName) 
    values(upper(@MakeName),@MakeIcon,@ImageName) 
END 

希望です

関連する問題