熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL語言 >> 正文

把圖片保存到數據庫的實現

2013-11-13 12:41:13  來源: SQL語言 

/// <summary>
/// 將照片轉換為二進制數組
/// </summary>
/// <param name=path></param>
/// <returns></returns>
private byte[] PhotoToArray( string path )
{
    FileStream stream = new FileStream( path FileModeOpen FileAccessRead ) ;
    byte[] bufferPhoto =new byte[streamLength] ;
    streamRead( bufferPhotoConvertToInt( streamLength ) ) ;
    streamFlush();
    streamClose();

    return bufferPhoto ;
}

//把二進制的圖片插到數據庫
private void Save(byte[] image)
{
    string sql = insert into table(aaaphoto) values(@aaa@photo);
    SqlParameter[] param=new SqlParameter[];
    param[] =new SqlParameter(@aaaSqlDbTypeInt);
    param[]Value = ;
    param[]= new SqlParameter(@photoSqlDbTypeImage);
    param[]Value= image;

    SqlConnection conn= new SqlConnection();
    connConnectionString = SystemConfigurationConfigurationSettingsAppSettings[];

    SqlCommand commd= new SqlCommand(sqlconn);
    commdParametersAdd(param[]);
    commdParametersAdd(param[]);

    try
    {
        connOpen();
        commdExecuteNonQuery();
        MessageBoxShow(把圖片成功的插入數據庫);
    }
    catch(Exception ex)
    {
        throw ex;
    }
    finally
    {
        connClose();
    }
}


From:http://tw.wingwit.com/Article/program/SQL/201311/16384.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.