GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  VB.NET
Go To First  |  Previous Question  |  Next Question 
 VB.NET  |  Question 19 of 60    Print  
How to store and retrieve images in sql server database through VB.NET

  
Total Answers and Comments: 3 Last Update: June 17, 2009     Asked by: Lakshmanan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 07, 2006 00:59:35   #1  
harsha        

RE: How to store and retrieve images in sql server dat...
SQL Server supports the ability for clients to store objects within tables
 
Is this answer useful? Yes | No
August 16, 2006 06:30:38   #2  
tapasvi darji        

RE: How to store and retrieve images in sql server dat...

To store image in database 1st u need to make table like this

CREATE TABLE PicImage
(
Picid int
Pic Image
)

Now in vb.net coding u have to write code like this

Dim ms As New MemoryStream

pic_photo.Image.Save(ms pic_photo.Image.RawFormat)

arrImage ms.GetBuffer

ms.Flush()

Now pass arrImage in ur insert query.


 
Is this answer useful? Yes | No
June 14, 2009 10:30:41   #3  
geocheru Member Since: June 2009   Contribution: 1    

RE: How to store and retrieve images in sql server database through VB.NET

Dim con As New SqlConnection _

("Server YourServer;uid ;pwd ;database northwind")

Dim da As New SqlDataAdapter _

("Select * From MyImages" con)

Dim MyCB As SqlCommandBuilder New SqlCommandBuilder(da)

Dim ds As New DataSet()


da.MissingSchemaAction MissingSchemaAction.AddWithKey


Dim fs As New FileStream _

("C:winntGone Fishing.BMP" FileMode.OpenOrCreate _

FileAccess.Read)

Dim MyData(fs.Length) As Byte

fs.Read(MyData 0 fs.Length)

fs.Close()

con.Open()

da.Fill(ds "MyImages")

Dim myRow As DataRow

myRow ds.Tables("MyImages").NewRow()


myRow("Description") "This would be description text"

myRow("imgField") MyData

ds.Tables("MyImages").Rows.Add(myRow)

da.Update(ds "MyImages")


fs Nothing

MyCB Nothing

ds Nothing

da Nothing


con.Close()

con Nothing

MsgBox ("Image saved to database")


Double-click Button2 and then add the following code to the Button2_Click
event handler:

Note You must change uid and pwd to the correct values before you run this
code. Make sure that User ID has the appropriate permissions to perform this
operation on the database.


Dim con As New SqlConnection _

("Server YourServer;uid ;pwd ;database northwind")

Dim da As New SqlDataAdapter _

("Select * From MyImages" con)

Dim MyCB As SqlCommandBuilder New SqlCommandBuilder(da)

Dim ds As New DataSet()


con.Open()

da.Fill(ds "MyImages")

Dim myRow As DataRow

myRow ds.Tables("MyImages").Rows(0)


Dim MyData() As Byte

MyData myRow("imgField")

Dim K As Long

K UBound(MyData)


Dim fs As New FileStream _

("C:winntGone Fishing2.BMP" FileMode.OpenOrCreate _

FileAccess.Write)

fs.Write(MyData 0 K)

fs.Close()


fs Nothing

MyCB Nothing

ds Nothing

da Nothing


con.Close()

con Nothing

MsgBox ("Image retrieved")


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape