+ Reply to Thread
Results 1 to 2 of 2




  

Thread: How to insert image in sql server?

      
  1. #1
    I'm New! jhonlever is on a distinguished road
    Join Date
    June 28, 2011
    Posts
    15
    Rep Power
    1
    Feedback Score
    0

    Default How to insert image in sql server?

    I am trying to insert images into a sql server database? I make the data type as image already but i dont know how to insert the image into the database? Any help will be great

  2. #2
    I'm New! Arielen is on a distinguished road
    Join Date
    July 5, 2011
    Posts
    3
    Rep Power
    0
    Feedback Score
    0

    Default Re: How to insert image in sql server?

    // Source Code for Save the image file into the database


    public void OnUpload(Object sender, EventArgs e)
    {
    // Create a byte[] from the input file

    int len = Upload.PostedFile.ContentLength;
    byte[] pic = new byte[len];
    Upload.PostedFile.InputStream.Read (pic, 0, len);
    // Insert the image and comment into the database

    SqlConnection connection = new
    SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=i ndia");
    try
    {
    connection.Open ();
    SqlCommand cmd = new SqlCommand ("insert into Image "
    + "(Picture, Comment) values (@pic, @text)", connection);
    cmd.Parameters.Add ("@pic", pic);
    cmd.Parameters.Add ("@text", Comment.Text);
    cmd.ExecuteNonQuery ();
    }
    finally
    {
    connection.Close ();
    }
    }
    try this code

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Anyone know how to insert dynamic data to a webpage?
    By giantimpact in forum Programming
    Replies: 1
    Last Post: Jan 18th, 2010, 1:56 pm
  2. How can I insert my own custom widget?
    By Kaos in forum Blogging
    Replies: 3
    Last Post: Jun 25th, 2008, 6:28 am
  3. Code Corrupted > Insert Fresh Copy
    By West in forum Feedback and Support
    Replies: 11
    Last Post: Nov 11th, 2006, 9:05 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
WebTalkForums
WebTalkForums
Recent Forum Threads