solve my problem

  • Thread starter Thread starter Ramesh Kumar via .NET 247
  • Start date Start date
R

Ramesh Kumar via .NET 247

(Type your message here)
Hi all,
Now I am doing my project using VC++/MFC and sql server as a database.I hava to store the Bitmaps in the database.If anybody knows about how to store the bitmap in the sql server as a BLOB object & retrive it.please help me it is urgent.
 
Hi Ramesh,

Sample code in VB. I made once, this uses a XML dataset, however that acts
the same as a database in this. It needs 4 buttons and a picturebox on a
form

I hope you get some idea's?

Cor
\\
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
 
Hi Rames,

I am not sure if this is the right place to ask the question since I am not
sure if you are using ado.net (vc++/mfc combination certainly doesn't use
it).
Anyway, here is the .net solution.
See
http://support.microsoft.com/default.aspx?scid=kb;en-us;309158&Product=adonet
and
http://support.microsoft.com/default.aspx?scid=kb;en-us;317016&Product=adonet.
They are in C# but you should easily convert them to whatever language
support .net.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Ramesh Kumar via .NET 247 said:
(Type your message here)
Hi all,
Now I am doing my project using VC++/MFC and sql server as a
database.I hava to store the Bitmaps in the database.If anybody knows about
how to store the bitmap in the sql server as a BLOB object & retrive
it.please help me it is urgent.
 
Back
Top