本文介绍了如何通过VB net将多个图像(blob)从SQL表保存到图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb net 2017.



通过这个下一个代码,我从sql表中获取请求IMAGE(归档名称为MMOBJS.LNL_BLOB)



 OpenConnection()

cmd = SqlCommand( 选择badge.ID,emp.SSNO,emp.LASTNAME,emp.FIRSTNAME,emp.MIDNAME,BADGSTAT.NAME,DEPT。 NAME,BADGE.ACTIVATE,BADGE.DEACTIVATE,MMOBJS.LNL_BLOB来自EMP内部联接BADGE EMP.ID = BADGE.EMPID INNER JOIN UDFEMP ON UDFEMP.ID = EMP.ID INNER JOIN DEPT UDFEMP.DEPT = DEPT.ID INNER JOIN BADGESTAT ON BADGE.STATUS = BADGSTAT.ID INNER JOIN MMOBJS ON MMOBJS.EMPID = BADGE.EMPID其中BADGE.ID喜欢'& DataGridView1.CurrentRow.Cells( 0 )。Value.ToString& %',connections)
reader = cmd.ExecuteReader()





我尝试过:



和下一个代码,我可以为一个选定的记录保存一个图像。



 如果 reader.Read =  False  然后 
MessageBox.Show( Фотодляпропуска№ &安培; DataGridView1.CurrentRow.Cells( 0 )。Value.ToString& нетвбазе。 消息,MessageBoxButtons.OK,MessageBoxIcon.Information)
否则

' 以字节为单位存储数据库中的图像值
Dim imageData 作为 字节()= reader( 9
如果 imageData 没什么 然后
使用 ms 作为 MemoryStream(imageData, 0 ,imageData.Length)
ms.Write(imageData, 0 ,imageData.Length)
pic_box.Image = Image.FromStream(ms, True

Dim 路径 As String = C:\ tmp2 \
Dim Dir As String = System .IO.Path.GetDirectoryName(路径)

尝试
尝试
如果 System.IO.Directory.Exists(Dir)然后
System.IO.Directory.CreateDirectory(Dir)
结束 如果

使用 sfdpic
。标题= 将图像保存为
.Filter = Jpg,Jpeg Images | * .jpg; * .jpeg
.AddExtension = True
.DefaultExt = 。jpg
' .FileName = txt_ssno.Text ++ txt_lname.Text ++ txt_fname.Text ++ txt_midname.Text
.FileName = DataGridView1.CurrentRow.Cells( 1 )。Value.ToString + + DataGridView1.CurrentRow.Cells( 2 )。Value.ToString + + DataGridView1.CurrentRow.Cells( 3 )。Value.ToString + + DataGridView1.CurrentRow.Cells( 4 )。Value.ToString
.OverwritePrompt = True
.InitialDirectory = Dir
.RestoreDirectory = True

如果 .ShowDialog = DialogResult.OK 那么
如果 .FilterIndex = 1 那么
pic_box.Image.Save(sfdpic.FileName,Imaging.ImageFormat.Jpeg)
结束 如果
结束 如果
结束 使用

Catch ex As 异常
MessageBox.Show( 错误:保存图像失败 - >>& ex.Message.ToString())

最后
sfdpic.Dispose()
结束 尝试

Catch ex As Exception
Me .Cursor = Cursors。 Default
MessageBox.Show(ex.Message, 消息,MessageBoxButtons.OK ,MessageBoxIcon.Information)
结束 尝试

结束 使用
结束 如果
reader.Close()
Cursor = Cursors。 D efault
结束 如果
Cursor = Cursors。默认

尝试







我无法为过滤的datagridview列表保存多个图像。我怎么能这样做?

请给我一个例子。

解决方案

I am using vb net 2017.

By this next code i get request IMAGE from sql table (filed name MMOBJS.LNL_BLOB)

     OpenConnection()

     cmd = New SqlCommand("Select badge.ID , emp.SSNO , emp.LASTNAME, emp.FIRSTNAME, emp.MIDNAME, BADGSTAT.NAME, DEPT.NAME , BADGE.ACTIVATE, BADGE.DEACTIVATE, MMOBJS.LNL_BLOB  FROM EMP INNER JOIN BADGE ON EMP.ID = BADGE.EMPID INNER JOIN UDFEMP ON UDFEMP.ID = EMP.ID INNER JOIN DEPT on UDFEMP.DEPT = DEPT.ID INNER JOIN BADGSTAT ON BADGE.STATUS = BADGSTAT.ID INNER JOIN MMOBJS ON MMOBJS.EMPID = BADGE.EMPID where BADGE.ID Like '" & DataGridView1.CurrentRow.Cells(0).Value.ToString & "%'", connections)
reader = cmd.ExecuteReader()



What I have tried:

and by next code, i can save one image for one selected record.

If reader.Read = False Then
     MessageBox.Show("Фото для пропуска № " & DataGridView1.CurrentRow.Cells(0).Value.ToString & " нет в базе.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else

     'store image value from the database in byte
     Dim imageData As Byte() = reader(9)
     If Not imageData Is Nothing Then
         Using ms As New MemoryStream(imageData, 0, imageData.Length)
             ms.Write(imageData, 0, imageData.Length)
             pic_box.Image = Image.FromStream(ms, True)

             Dim Path As String = "C:\tmp2\"
             Dim Dir As String = System.IO.Path.GetDirectoryName(Path)

             Try
                 Try
                     If Not System.IO.Directory.Exists(Dir) Then
                         System.IO.Directory.CreateDirectory(Dir)
                     End If

                     With sfdpic
                         .Title = "Save image As"
                         .Filter = "Jpg, Jpeg Images|*.jpg; *.jpeg"
                         .AddExtension = True
                         .DefaultExt = ".jpg"
                         '.FileName = txt_ssno.Text + " " + txt_lname.Text + " " + txt_fname.Text + " " + txt_midname.Text
                         .FileName = DataGridView1.CurrentRow.Cells(1).Value.ToString + " " + DataGridView1.CurrentRow.Cells(2).Value.ToString + " " + DataGridView1.CurrentRow.Cells(3).Value.ToString + " " + DataGridView1.CurrentRow.Cells(4).Value.ToString
                         .OverwritePrompt = True
                         .InitialDirectory = Dir
                         .RestoreDirectory = True

                         If .ShowDialog = DialogResult.OK Then
                             If .FilterIndex = 1 Then
                                 pic_box.Image.Save(sfdpic.FileName, Imaging.ImageFormat.Jpeg)
                             End If
                         End If
                     End With

                 Catch ex As Exception
                     MessageBox.Show("Error: Saving Image Failed ->>" & ex.Message.ToString())

                 Finally
                     sfdpic.Dispose()
                 End Try

             Catch ex As Exception
                 Me.Cursor = Cursors.Default
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
             End Try

         End Using
     End If
     reader.Close()
     Cursor = Cursors.Default
 End If
 Cursor = Cursors.Default

 Try




I cannot save multiple image for filtered datagridview list. How can i do it?
Any example please.

解决方案


这篇关于如何通过VB net将多个图像(blob)从SQL表保存到图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:41