Remember that you will store the binary image's information in a binary filed in your DataBase.
Imports System.Data.SqlClient
Imports System.IO
'>>>>In another button:>>>>
Dim oCnx As NewSqlConnection("SOMESTRINGCONNECTION")
Dim oDa As New SqlDataAdapter("Select * From ANYTABLE", oCnx)
Dim oCB As SqlCommandBuilder = New SqlCommandBuilder(oDa)
Dim oDs As New DataSet()
oDa.MissingSchemaAction = MissingSchemaAction.AddWithKey
oCnx.Open()
oDa.Fill(ds, "ANYTABLE")
Dim oFs As New FileStream ("c:\image.jpg", FileMode.OpenOrCreate, FileAccess.Read)
Dim MyData(oFs.Length) As Byte
oFs.Read(MyData, 0, oFs.Length)
oFs.Close()
oDs.Tables("ANYTABLE").Rows(0)("SOMENAME") = MyData
oDa.Update(oDs, "ANYTABLE")
oFs = Nothing
oCB = Nothing
oDs = Nothing
oDa = Nothing
oCnx.Close()
oCnx = Nothing
Response.Write("Image was saved to DB")
For retrieve that image, you get tha binary information and you will put it into a file.
Imports System.Data.SqlClient
Imports System.IO
'>>>>In a button:>>>>
Dim oCnx As New SqlConnection("SOMESTRINGCONNECTION")
Dim oDa As New SqlDataAdapter("Select * From ANYTABLE", oCnx)
Dim oCB As SqlCommandBuilder = New SqlCommandBuilder(oDa)
Dim oDs As New DataSet()
oCnx.Open()
oDa.Fill(oDs, "ANYTABLE")
Dim oRow As DataRow
oRow = oDs.Tables("ANYTABLE").Rows(0)
Dim MyData() As Byte
MyData = oRow("SOMENAME")
Response.Buffer = True
Response.ContentType = "Image/JPEG"
Response.BinaryWrite(MyData)
oCB = Nothing
oDs = Nothing
oDa = Nothing
oCnx.Close()
oCnx = Nothing
Good luck!,
l-touched
----- Steven Caliendo wrote: -----
Hi,
Can someone give me an example of a query that will update a database with
an Image type ? So, if I have a picture file on my web server, and I want
to add it to my SQL database in a field defined as Image, what query do I
use ? Insert into Picture values (?????)
Thanks,
Steve