C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Images »

How To Insert Image Into Database


Posted Date: 23 Sep 2008    Resource Type: Code Snippets    Category: Images
Author: nirmalaMember Level: Gold    
Rating: 1 out of 5Points: 10



hi
try for this code: insert image in to database.


.aspx:

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server" Style="left: 380px; position: relative;
top: -401px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

.cs:

page_load()
{
// give sql connections(connection string)
}
protected void Button1_Click(object sender, EventArgs e)
{
int len = FileUpload1.PostedFile.ContentLength;

byte[] pic = new byte[len];
FileUpload1.PostedFile.InputStream.Read(pic, 0, len);
string fup = FileUpload1.PostedFile.FileName;


if (k1 == 0)
{
cmd = new SqlCommand("insert into login_inf(first_name,logo) values (@name,@logo)", conn);


cmd.Parameters.Add("@name", TextBox1.Text.Replace("'", "''"));

cmd.Parameters.Add("@logo", pic);
cmd.ExecuteNonQuery();

}
}


Attachments

  • "Insert Image.aspx" (21412-23041-insertimage.txt)


  • Responses

    Author: n.ravi krishna    13 Feb 2009Member Level: Silver   Points : 0
    good programming.exellent.


    Author: Sasikumar    16 Feb 2009Member Level: Gold   Points : 1
    This was nice Code:

    It works fine for me, i am able to upload an Image

    How can i Retrieve the Image to Front End,through grid view to the image field
    Please Send Me the Code

    Thanks and Regards
    Sasikumar


    Author: skc    12 Mar 2009Member Level: Bronze   Points : 1
    Hi should i need to create at table login_inf
    cmd = new SqlCommand("insert into login_inf(first_name,logo) values (@name,@logo)", conn);


    Author: ankit    18 Mar 2009Member Level: Bronze   Points : 0
    this is a good code for inserting an image.
    Thanks for such a nice code.


    Author: Shuby Arora    24 May 2009Member Level: Gold   Points : 0
    Hi
    THis is a good code

    keep it up!


    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    "Insert Image Into Database"  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Images upload to server
    Previous Resource: "Retriving Image From Database By Using FormatUrl"
    Return to Discussion Resource Index
    Post New Resource
    Category: Images


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use