• <legend id='tggl8'><style id='tggl8'><dir id='tggl8'><q id='tggl8'></q></dir></style></legend>

    <tfoot id='tggl8'></tfoot>

  • <small id='tggl8'></small><noframes id='tggl8'>

      <i id='tggl8'><tr id='tggl8'><dt id='tggl8'><q id='tggl8'><span id='tggl8'><b id='tggl8'><form id='tggl8'><ins id='tggl8'></ins><ul id='tggl8'></ul><sub id='tggl8'></sub></form><legend id='tggl8'></legend><bdo id='tggl8'><pre id='tggl8'><center id='tggl8'></center></pre></bdo></b><th id='tggl8'></th></span></q></dt></tr></i><div id='tggl8'><tfoot id='tggl8'></tfoot><dl id='tggl8'><fieldset id='tggl8'></fieldset></dl></div>

      • <bdo id='tggl8'></bdo><ul id='tggl8'></ul>

      1. 如何使用 vb.net 和 adodb 连接在 mysql 数据库中插入图像

        时间:2023-09-17
          <tbody id='X0KHk'></tbody>

        <legend id='X0KHk'><style id='X0KHk'><dir id='X0KHk'><q id='X0KHk'></q></dir></style></legend>

            <tfoot id='X0KHk'></tfoot>
          1. <i id='X0KHk'><tr id='X0KHk'><dt id='X0KHk'><q id='X0KHk'><span id='X0KHk'><b id='X0KHk'><form id='X0KHk'><ins id='X0KHk'></ins><ul id='X0KHk'></ul><sub id='X0KHk'></sub></form><legend id='X0KHk'></legend><bdo id='X0KHk'><pre id='X0KHk'><center id='X0KHk'></center></pre></bdo></b><th id='X0KHk'></th></span></q></dt></tr></i><div id='X0KHk'><tfoot id='X0KHk'></tfoot><dl id='X0KHk'><fieldset id='X0KHk'></fieldset></dl></div>

              <bdo id='X0KHk'></bdo><ul id='X0KHk'></ul>

                • <small id='X0KHk'></small><noframes id='X0KHk'>

                  本文介绍了如何使用 vb.net 和 adodb 连接在 mysql 数据库中插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 vb.net 2008 中使用 adodb 连接将图像插入到 mysql 数据库中.

                  I want to insert an image into a mysql database using the adodb connection in vb.net 2008.

                  我正在使用选择查询将数据插入数据库,这是我添加或保存数据的代码...

                  I am using a select query to insert data into database, here is my code for adding or saving data...

                      rs.Open("select * from registration where Debt_ID = '" & txtDebt_ID.Text & "' ", cnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic)
                      If rs.RecordCount = 1 Then
                          MsgBox("ID already exist!", MsgBoxStyle.Exclamation, vbOK)
                          rs.Close()
                          cnn.Close() 
                  
                          Exit Sub
                      Else
                  
                          rs.AddNew()
                          rs.Fields("Debt_ID").Value = txtDebt_ID.Text
                          rs.Fields("LastName").Value = txt_Lastname.Text
                          rs.Fields("firstName").Value = txt_Firstname.Text
                          rs.Fields("MiddleName").Value = txt_Middlename.Text
                          rs.Fields("age").Value = txt_Age.Text
                          rs.Fields("birthdate").Value = txt_Birthdate.Text
                          rs.Fields("civil_status").Value = txtCivil_status.Text
                          rs.Fields("address").Value = txt_Address.Text
                          rs.Fields("occupation").Value = txt_Address.Text
                          rs.Fields("contact_no").Value = txt_Contact.Text
                          'rs.Fields("picture").Value = PictureBox1.Image
                          rs.Save()
                          rs.Close()
                      End If
                  

                  我想将数据库中的图像添加到字段图片中,并且我使用 blob 作为我的数据类型,我还想从数据库中检索图像并将其显示在图片框中...有人可以吗帮助解决我的问题.

                  I wanted to add an image on the database into the field picture and I'm using blob as my datatype for it, I also want to retrieve the image from the database and display it in a picturebox... can someone please help regarding my problem.

                  提前致谢...

                  推荐答案

                  无论使用何种数据访问技术或数据库,都需要将 am Image 转换为 Byte> 首先,然后保存.在检索时,您将 Byte 数组转换回 Image.

                  Regardless of what data access technology or database you use, you need to convert am Image to a Byte first and then save that. On retrieval, you convert the Byte array back to an Image.

                  保存:

                  Dim connection As New SqlConnection("connection string here")
                  Dim command As New SqlCommand("UPDATE MyTable SET Picture = @Picture WHERE ID = 1", connection)
                  
                  'Create an Image object.'
                  Using picture As Image = Image.FromFile("file path here")
                      'Create an empty stream in memory.'
                      Using stream As New IO.MemoryStream
                          'Fill the stream with the binary data from the Image.'
                          picture.Save(stream, Imaging.ImageFormat.Jpeg)
                  
                          'Get an array of Bytes from the stream and assign to the parameter.'
                          command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = stream.GetBuffer()
                      End Using
                  End Using
                  
                  connection.Open()
                  command.ExecuteNonQuery()
                  connection.Close()
                  

                  检索:

                  Dim connection As New SqlConnection("connection string here")
                  Dim command As New SqlCommand("SELECT Picture FROM MyTable WHERE ID = 1", connection)
                  
                  connection.Open()
                  
                  Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
                  
                  connection.Close()
                  
                  Dim picture As Image = Nothing
                  
                  'Create a stream in memory containing the bytes that comprise the image.'
                  Using stream As New IO.MemoryStream(pictureData)
                      'Read the stream and create an Image object from the data.'
                      picture = Image.FromStream(stream)
                  End Using
                  

                  该示例适用于 ADO.NET 和 SQL Server,但无论如何使用 MemoryStream 进行转换的原理是相同的.

                  That example is for ADO.NET and SQL Server but the principle of using a MemoryStream for the conversion is the same regardless.

                  这篇关于如何使用 vb.net 和 adodb 连接在 mysql 数据库中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:防止重复进入数据库 下一篇:在 Python 中将 MySQL 与 AWS Lambda 结合使用的问题

                  相关文章

                  <legend id='6Hn5w'><style id='6Hn5w'><dir id='6Hn5w'><q id='6Hn5w'></q></dir></style></legend>
                  <tfoot id='6Hn5w'></tfoot>
                      <bdo id='6Hn5w'></bdo><ul id='6Hn5w'></ul>

                  1. <small id='6Hn5w'></small><noframes id='6Hn5w'>

                    1. <i id='6Hn5w'><tr id='6Hn5w'><dt id='6Hn5w'><q id='6Hn5w'><span id='6Hn5w'><b id='6Hn5w'><form id='6Hn5w'><ins id='6Hn5w'></ins><ul id='6Hn5w'></ul><sub id='6Hn5w'></sub></form><legend id='6Hn5w'></legend><bdo id='6Hn5w'><pre id='6Hn5w'><center id='6Hn5w'></center></pre></bdo></b><th id='6Hn5w'></th></span></q></dt></tr></i><div id='6Hn5w'><tfoot id='6Hn5w'></tfoot><dl id='6Hn5w'><fieldset id='6Hn5w'></fieldset></dl></div>