BLOG用SQL语句是不能直接插入的,必须先插入一个空数据empty_blob(),然后再 private void SaveFile(int data_id,byte[] p_Blob,string id,string photo,string tablename,OracleConnection mConn) { try { OracleDataAdapter photoAdapter; DataSet photoDataSet; DataTable photoTable; DataRow photoRow; photoAdapter = new OracleDataAdapter( "SELECT "+id+","+photo+"" + " FROM "+tablename+" WHERE "+id+" = " + data_id,mConn); photoDataSet= new DataSet(tablename); photoAdapter.UpdateCommand = new OracleCommand ("UPDATE "+tablename+" SET " + ""+photo+" = :vPHOTO " + "WHERE "+id+" = :vID",mConn); photoAdapter.UpdateCommand.Parameters.Add(":vPHOTO", OracleType.Blob, p_Blob.Length, photo); photoAdapter.UpdateCommand.Parameters.Add(":vID", OracleType.Int32, 0, id); photoAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; // Configures the schema to match with Data Source photoAdapter.FillSchema(photoDataSet, SchemaType.Source, tablename); // Fills the DataSet with 'drivers' table data photoAdapter.Fill(photoDataSet,tablename); // Get the current driver ID row for updation photoTable = photoDataSet.Tables[tablename]; photoRow = photoTable.Rows.Find(data_id); // Start the edit operation on the current row in // the 'drivvers' table within the dataset. photoRow.BeginEdit(); // Assign the value of the Photo if not empty if (p_Blob.Length != 0) { photoRow[photo] = p_Blob; } // End the editing current row operation photoRow.EndEdit(); // Update the database table 'drivers' photoAdapter.Update(photoDataSet,tablename); } catch(Exception e) { throw e; } } #endregion用DATASET 方式插入数据
<add key="ConString" value="Data Source=int64;User Id=center;Password=center;" />如果是Oracle9,那么要注意权限的设置
private void SaveFile(int data_id,byte[] p_Blob,string id,string photo,string tablename,OracleConnection mConn)
{
try
{
OracleDataAdapter photoAdapter;
DataSet photoDataSet;
DataTable photoTable;
DataRow photoRow; photoAdapter = new OracleDataAdapter(
"SELECT "+id+","+photo+"" +
" FROM "+tablename+" WHERE "+id+" = " + data_id,mConn);
photoDataSet= new DataSet(tablename);
photoAdapter.UpdateCommand = new OracleCommand
("UPDATE "+tablename+" SET " +
""+photo+" = :vPHOTO " +
"WHERE "+id+" = :vID",mConn);
photoAdapter.UpdateCommand.Parameters.Add(":vPHOTO",
OracleType.Blob, p_Blob.Length, photo);
photoAdapter.UpdateCommand.Parameters.Add(":vID",
OracleType.Int32, 0, id); photoAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; // Configures the schema to match with Data Source
photoAdapter.FillSchema(photoDataSet, SchemaType.Source, tablename); // Fills the DataSet with 'drivers' table data
photoAdapter.Fill(photoDataSet,tablename); // Get the current driver ID row for updation
photoTable = photoDataSet.Tables[tablename];
photoRow = photoTable.Rows.Find(data_id); // Start the edit operation on the current row in
// the 'drivvers' table within the dataset.
photoRow.BeginEdit();
// Assign the value of the Photo if not empty
if (p_Blob.Length != 0)
{
photoRow[photo] = p_Blob;
}
// End the editing current row operation
photoRow.EndEdit(); // Update the database table 'drivers'
photoAdapter.Update(photoDataSet,tablename); }
catch(Exception e)
{
throw e;
}
} #endregion用DATASET 方式插入数据
parameter.OracleType = OracleType.Blob
parameter.Value = System.Byte[]类型的变量