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

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

2022-06-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-2022 電腦知識網 Computer Knowledge   All rights reserved.