C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Save image file into SQL Server without using Stored Proc


Posted Date: 19 Feb 2007    Resource Type: Code Snippets    Category: SQL

Posted By: Tony John       Member Level: Gold
Rating:     Points: 10



This code shows how to use a simple insert sql query to save an image file into SQL Server.

Related Articles: Save image using stored proc


Public Sub SaveImageFileToDatabase(ByVal imagefilePath As String)
' Define a stream to convert the file into bytes.
Dim fs As New FileStream(imagefilePath, FileMode.Open)

' Define an array of bytes with a size equal to the length of image content
Dim data() As Byte = New [Byte](fs.Length) {}

' Read the image data into the byte array
fs.Read(data, 0, fs.Length)

' Create an sql connection object
Dim connection As New System.Data.SqlClient.SqlConnection("data source=(local);initial catalog=MyDatabaseName;user id=John;password=LittleBird")
connection.Open()

' Execute the query to save bytes into database table.
Dim cmd As SqlCommand = New SqlCommand
cmd.Connection = connection
cmd.CommandText = "insert imagetable values(@img)"
cmd.Parameters.Add(New SqlParameter("@img", SqlDbType.Image)).Value = data
cmd.ExecuteNonQuery()

connection.Close()
End Sub




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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.
Previous Resource: Save an image file to database using a stored proc
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it support

Contact Us    Privacy Policy    Terms Of Use