2

I use System.Data.SQLite library for working with databse file, avoiding any specific class names connected with that library, using interface names. e.g. IDbConnection = new SQLiteConnection, and etc.

So Instead of SQLiteCommand i have IDbCommand interface instance. The problem that i want to add BLOB data into my command and i cannot do this, as IDbCommand.Properties.Add() has no suitable implementation for me - it only accepts object parameter.

I cannot use SQLiteCommand class name explicitly, so i need to find some proper way to do as in example i've found (http://www.akadia.com/services/dotnet_read_write_blob.html):

sqliteCommand.Parameters.Add("@Photo",    
    SqlDbType.Image, photo.Length).Value = photo;

Why do i do like this? In future, i probably will use my code for remote SQL connections, not just SQLite.... Really need to find some solution...

Thank you!

4
  • What is the type of photo? is it a byte[] ? Also: do you mean IDbCommand.Parameters.Add()? Commented Oct 15, 2014 at 15:48
  • @Marc Gravell, of course, as i am talking about blobs, this code sample is from link mentioned in text. 2) yes Commented Oct 15, 2014 at 15:50
  • "blobs" is vague, hence why I wanted to be clearer. There are often vendor-specific blob types that can be used. Commented Oct 15, 2014 at 15:52
  • Well... Hope it's not too different.. as i understand it's just a byte data and its length. Commented Oct 15, 2014 at 16:03

1 Answer 1

2

Basically:

IDbDataParameter param = cmd.CreateParamter();
param.ParameterName = "@Photo";
param.Value = blob;
param.Size = blob.Length;
param.DbType = DbType.Binary;
cmd.Parameters.Add(param);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.