-1

I’m using database utility and in this example I’m inserting some records

DBUtil.ExecuteNonQuery(@"if not exists(select * from UserTemplate)
   begin
     insert into UserTemplate
     select id, 8,1,….{TemplateCode} ….
     from User
  end”);

how can I extend this query to select UsersImage column from UserTemplate table?

P.S. UsersImage is of varbinary(MAX) datatype.

Maverick
  • 1,396
  • 5
  • 22
  • 42
panjo
  • 3,467
  • 11
  • 48
  • 82
  • That does not return a result set. You will need to rewrite the SQL statement and use a different method of `DBUtil`. – Crowcoder Jan 02 '16 at 12:40
  • maybe I left something in a hurry, but question is how to extend the query to select UsersImage from UserTemplate table knowing that UsersImage is varbinary(MAX)? – panjo Jan 02 '16 at 13:27

1 Answers1

0

Without knowing what DBUtil is, or if you want one specific image or all of them, I would guess you want something like this. Execute a reader that gets all images, read the varbinary field into a byte array, do something with the byte array.

using(SqlDataReader rdr = DBUtil.ExecuteReader("SELECT [UsersImage] FROM [UserTemplate]"))
{
    while(rdr.Read())
    {
        btye[] img = (byte[])rdr[0];
        //do something with img
    }
}
Crowcoder
  • 11,250
  • 3
  • 36
  • 45