技术开发 频道

运用C#处理lob数据类型


【IT168技术文档】

#region 更新blob字段 UpdateBlob(string strTableName, string blobColumn, byte[] blobValue, string strCondition) /// <summary> /// 更新blob字段 /// </summary> /// <param name="strTableName">表名</param> /// <param name="blobColumn">列名</param> /// <param name="blobValue">Blob值</param> /// <param name="strCondition">条件</param> public static void UpdateBlob(string strTableName, string blobColumn, byte[] blobValue, string strCondition) { string strConnectionString ="user id= " + ProfileModel.strUserName + ";" + "data source=" + ProfileModel.strServerSource + " ;password= " +ProfileModel.strPassword ; string strSelectSql = "SELECT * FROM " + strTableName; strSelectSql += " WHERE " + strCondition; string strUpdateSql = "UPDATE " + strTableName + " SET " + blobColumn + " = :BlobValue "; strUpdateSql += " WHERE " + strCondition; OracleConnection blobConnection = new OracleConnection(strConnectionString);; OracleDataAdapter blobAdapter; DataSet blobDataSet; DataTable blobTable; DataRow blobRow; try { blobConnection.Open(); blobAdapter = new OracleDataAdapter(strSelectSql, blobConnection); blobAdapter.UpdateCommand = new OracleCommand(strUpdateSql, blobConnection); blobAdapter.UpdateCommand.Parameters.Add(":BlobValue", OracleType.Blob, blobValue.Length, blobColumn); blobDataSet = new DataSet(strTableName); blobAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; blobAdapter.FillSchema(blobDataSet, SchemaType.Source, strTableName); blobAdapter.Fill(blobDataSet,strTableName); blobTable = blobDataSet.Tables[strTableName]; blobRow = blobTable.Rows[0]; blobRow.BeginEdit(); if (blobValue.Length != 0) { blobRow[blobColumn] = blobValue; } blobRow.EndEdit(); blobAdapter.Update(blobDataSet,strTableName); } catch(Exception e) { Console.WriteLine("DbAccess.UpdateBlob() Error" + e.Message); throw new Exception("DbAccess.UpdateBlob() Error" + e.Message); } finally { blobConnection.Close(); } } #endregion
0
相关文章