Click here to Skip to main content
16,004,895 members
Home / Discussions / C#
   

C#

 
GeneralRe: Custom project and custom code pages Pin
narada10818-May-04 6:47
narada10818-May-04 6:47 
GeneralRe: Custom project and custom code pages Pin
Heath Stewart18-May-04 6:57
protectorHeath Stewart18-May-04 6:57 
GeneralRe: Custom project and custom code pages Pin
narada10818-May-04 7:01
narada10818-May-04 7:01 
GeneralRe: Custom project and custom code pages Pin
narada10819-May-04 2:55
narada10819-May-04 2:55 
GeneralWindows media encoder and server Pin
koala8118-May-04 0:24
koala8118-May-04 0:24 
GeneralRe: Windows media encoder and server Pin
Dave Kreskowiak18-May-04 2:29
mveDave Kreskowiak18-May-04 2:29 
GeneralPic in databse Pin
sreejith ss nair17-May-04 23:58
sreejith ss nair17-May-04 23:58 
GeneralRe: Pic in databse Pin
Heath Stewart18-May-04 4:21
protectorHeath Stewart18-May-04 4:21 
Create a binary field (like an image field type in your database to store these images. Then use a SqlParameter for your SqlCommand like so:
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO MyTable (Image) VALUES (@Image)";
SqlParameter image = cmd.Parameters.Add("@Image", SqlDbType.Image);
using (MemoryStream ms = new MemoryStream())
{
  bmp.Save(ms, ImageFormat.Jpeg);
  ms.Seek(0, SeekOrigin.Begin);
  byte[] buffer = new byte[ms.Length];
  ms.Read(buffer, 0, buffer.Length);
  image.Value = buffer;
}
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
You should, of course, add some exception handling. How you get the image data isn't so much important as how you store it.

Another alternative is to use your database as a file system and only store a reference to the image files. This make it easier to display the images in a web page since you don't have to worry about either saving the images to a virtual directory when requested, or writing a handler (perhaps even an ASP.NET .aspx page) to extract the data on the fly (if you do, youmight consider caching against the query string params). This is what we do for the documen management portion of our application.

 

Microsoft MVP, Visual C#
My Articles
Generalthe global Hook doesnt work Pin
fu017-May-04 23:34
fu017-May-04 23:34 
GeneralRe: the global Hook doesnt work Pin
Dave Kreskowiak18-May-04 2:27
mveDave Kreskowiak18-May-04 2:27 
GeneralRe: the global Hook doesnt work Pin
fu019-May-04 23:28
fu019-May-04 23:28 
GeneralRe: the global Hook doesnt work Pin
Dave Kreskowiak20-May-04 0:54
mveDave Kreskowiak20-May-04 0:54 
GeneralStarting a Crystal Report on another databaseserver Pin
jvbragt17-May-04 22:33
jvbragt17-May-04 22:33 
GeneralRe: Starting a Crystal Report on another databaseserver Pin
Heath Stewart18-May-04 4:28
protectorHeath Stewart18-May-04 4:28 
Generaloops Pin
sreejith ss nair17-May-04 21:35
sreejith ss nair17-May-04 21:35 
GeneralRe: oops Pin
Daniel Turini18-May-04 0:42
Daniel Turini18-May-04 0:42 
GeneralRe: oops Pin
Aryadip18-May-04 0:57
Aryadip18-May-04 0:57 
GeneralViewing ascii in datagrid Pin
dabuskol17-May-04 21:32
dabuskol17-May-04 21:32 
GeneralRe: Viewing ascii in datagrid Pin
Heath Stewart18-May-04 4:31
protectorHeath Stewart18-May-04 4:31 
Generaloops Pin
sreejith ss nair17-May-04 21:31
sreejith ss nair17-May-04 21:31 
GeneralImage Rotation in C# Pin
mmxguy17-May-04 21:07
mmxguy17-May-04 21:07 
GeneralMessage Removed Pin
17-May-04 23:21
wibblewibblewibble17-May-04 23:21 
GeneralRe: Image Rotation in C# Pin
mmxguy18-May-04 0:00
mmxguy18-May-04 0:00 
GeneralRe: Image Rotation in C# Pin
Heath Stewart18-May-04 3:40
protectorHeath Stewart18-May-04 3:40 
GeneralWriting a bot in C# Pin
kashif Syed17-May-04 20:42
kashif Syed17-May-04 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.