Example #1
0
 /// <summary>
 /// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例)
 /// </summary>
 /// <param name="strSql">SQL语句</param>
 /// <param name="fs">图像字节,数据库的字段类型为image的情况</param>
 /// <returns>影响的记录数</returns>
 public static int ExecuteSqlInsertImg(string strSql, byte[] data)
 {
     using (OleDbConnection conn = ConnectionMgr.GetOleDbConnection())
     {
         int ret = 0;
         conn.Open();
         OleDbCommand cmd = conn.CreateCommand();
         cmd.CommandText = strSql;
         OleDbParameter para = cmd.CreateParameter();
         para.Direction = ParameterDirection.Input;
         para.DbType    = DbType.Binary;
         para.Value     = data;
         cmd.Parameters.Add(para);
         try
         {
             ret = cmd.ExecuteNonQuery();
         }
         catch (DbException ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
         return(ret);
     }
 }
Example #2
0
 /// <summary>
 /// 带有图片数据的查询
 /// </summary>
 /// <param name="SQLString"></param>
 /// <returns></returns>
 public static DataSet QueryWithImageData(string SQLString)
 {
     using (OleDbConnection conn = ConnectionMgr.GetOleDbConnection())
     {
         DataSet ds = new DataSet();
         try
         {
             conn.Open();
             OleDbCommand     cmd = new OleDbCommand(SQLString, conn);
             OleDbDataAdapter da  = new OleDbDataAdapter();
             da.SelectCommand = cmd;
             da.Fill(ds, "ds");
         }
         catch (DbException ex)
         {
             throw new Exception(ex.Message);
         }
         finally
         {
             conn.Close();
         }
         return(ds);
     }
 }