Здравствуйте, frantic_aleks, Вы писали:
_>Необходимо сохранить любой файл в поле базы Access. Тип поля пробовал ставить MEMO и Объект OLE. Сохраняются файлы размером не более пару сотен байт. Для больших файлов дравер ODBC выдаёт ошибку — превышена точность поля.
_>Вот пример кода:
_>_> byte[] content = new byte[stream.Length];
_> // ...
_> OdbcConnection conn = new OdbcConnection(connStr);
_> conn.Open();
_> OdbcCommand cmd = new OdbcCommand(
_> "UPDATE Repository SET Content = ?"
_> +" WHERE ID = "+ID, conn);
_> OdbcParameter param = cmd.CreateParameter();
_> param.OdbcType = OdbcType.Binary;
_> param.Value = content;
_> cmd.Parameters.Add(param);
_> cmd.ExecuteNonQuery();
_>
_>Буду благодарен за любую помощь.
Я бы использовал OLEDB... (возможно OdbcConnection и т.д. не будут поддерживаться в новых версиях фрэймворк)
public class SimpleQuery
{
OleDbConnection connection;
OleDbCommand command;
OleDbDataReader reader;
bool eof;
<skip>
public bool blob2bytes( string sqlstr, string field, ref byte[] b )
{
try
{
Close();
if ( connection.State == System.Data.ConnectionState.Closed )
connection.Open();
if ( command != null )
{
command.CommandText = sqlstr;
command.Connection = connection;
}
else
command = new OleDbCommand( sqlstr, connection );
if ( reader == null )
reader = command.ExecuteReader();
reader.Read();
int fieldIndex = reader.GetOrdinal( field );
b = new byte[ Convert.ToInt32( reader.GetBytes( fieldIndex, 0, null, 0, Int32.MaxValue ) ) ];
reader.GetBytes( fieldIndex , 0, b, 0, b.Length);
return true;
}
catch ( Exception ex )
{
error = ex.Message;
if ( msgerror )
MessageBox.Show(null, ex.Message, "error reading data");
}
finally
{
Close();
}
return false;
}
public bool bytes2blob( ref byte[] b, int size, string sqlstr, string field )
{
try
{
Close();
if ( connection.State == System.Data.ConnectionState.Closed )
connection.Open();
if ( command != null )
{
command.CommandText = sqlstr;
command.Connection = connection;
}
else
command = new OleDbCommand( sqlstr, connection );
OleDbParameter parameter = new OleDbParameter( "@" + field,
OleDbType.LongVarBinary,
b.Length,
ParameterDirection.Input,
false, 0, 0, null,
DataRowVersion.Current, b);
command.Parameters.Add( parameter );
command.ExecuteNonQuery();
command.Parameters.Clear();
return true;
}
catch(Exception ex)
{
error = ex.Message;
if ( msgerror )
MessageBox.Show(null, ex.Message, "error writing data");
}
return false;
}
}