图像存储和来回访问vb 2008 [英] image store and retrieve fro access vb 2008

查看:47
本文介绍了图像存储和来回访问vb 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我叫Mujeeb.

我在vb 2008中启动了一个小的学生表(数据库是access 2007),我成功保存了图像以访问vb 2008槽,但是我无法从该访问中检索图像有人可以帮我吗,我将保存代码粘贴到这里

Hi All, I am Mujeeb.

I Started a small student Table in vb 2008 (DB is access 2007) ,I Succeed to Save image to access trough vb 2008 but I could not retrieve the image from the access Can Some One help me I am Pasting the save code here

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Dim SQLStr As String = ""
        If newmode = True Then
            SQLStr = "insert into Students_Data(Regi_No,Gender,Student_Name,Date_Of_Birth,Father_Name,Mother_Name,Place_Address,Contact_No,Date_Of_Joining,photo) values(?,?,?,?,?,?,?,?,?,?)"
        Else
            SQLStr = "Update Students_Data set Regi_No=?,Gender=?,Student_Name=?,Date_Of_Birth=?,Father_Name=?,Mother_Name=?,Place_Address=?,Contact_No=?,Date_Of_Joining=?,photo=? Where Regi_No = " & cmbregno.Text & " "
        End If
        Dim Transaction As System.Data.OleDb.OleDbTransaction = _app.DataBaseName.BeginTransaction
        Dim InputData As New System.Data.OleDb.OleDbCommand(SQLStr, _app.DataBaseName, Transaction)

        InputData.Parameters.Add("@Regi_No", cmbregno.Text)
        InputData.Parameters.Add("@Gender", cmbgender.Text)
        InputData.Parameters.Add("@Student_Name", txtstudname.Text)
        InputData.Parameters.Add("@Date_Of_Birth", dtdob.Value).DbType = DbType.Date
        InputData.Parameters.Add("@Father_Name", txtfathername.Text)
        InputData.Parameters.Add("@Mother_Name", txtmothername.Text)
        InputData.Parameters.Add("@Place_Address", txtplaceaddress.Text)
        InputData.Parameters.Add("@Contact_No", txtcontactno.Text)
        InputData.Parameters.Add("@Date_Of_Joining", dtjoining.Value).DbType = DbType.Date
      
        InputData.Parameters.Add("@Photo", picstud.Image)
        Try
            InputData.ExecuteNonQuery()
            Transaction.Commit()
        Catch ex As Exception
            MsgBox(ex.Message)
            Transaction.Rollback()
        Finally
            InputData.Dispose()
        End Try
       

    End Sub



我使用A类连接了数据库
下面的代码



I Connected the DB using A class
Code Below

Public Class application
    Dim _dataBasename As System.Data.OleDb.OleDbConnection
    Public Property DataBaseName()
        Get
            Return _dataBasename
        End Get
        Set(ByVal Value)
            _dataBasename = Value
        End Set
    End Property
    Function ConData()
        Try
            _dataBasename = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & "D:\School\School.mdb" & "'")
           
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
        _dataBasename.Open()
    End Function
End Class




希望很快得到答复
谢谢大家
Mujeeb




I hope to get a reply soon
Thanks all
Mujeeb

推荐答案

不,这不起作用.

No, that won''t work.

InputData.Parameters.Add("@Photo", picstud.Image)

这不会将Image本身放入数据库中,而是将字符串"System.Drawing.Image"放入数据库中,因为将使用默认的ToString实现.
而是将Image转换为字节数组:

That will not put the Image itself into the database, it will put the string "System.Drawing.Image" into the database instead, as the default ToString implementation will be used.
Instead, convert the Image to an array of bytes:

Dim ms As New MemoryStream()
picstud.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
InputData.Parameters.Add("@Photo", ms.ToArray())


然后,您可以将其读出并转换回图像:


You can then read it back out and convert it back to an Image:

Dim bytes As Byte() = DirectCast(dataReader("photo"), Byte())
Dim ms As New MemoryStream(bytes)
Dim returnImage As Image = Image.FromStream(ms)


这篇关于图像存储和来回访问vb 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆