Vb.net VIS2017和sqlite图像从DB到带有数据读取器的图片框。 [英] Vb.net VIS2017 and sqlite image from DB to picture box with data reader.

查看:97
本文介绍了Vb.net VIS2017和sqlite图像从DB到带有数据读取器的图片框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我一直试图在我的应用程序中添加一些数据库功能而没有太多运气。请记住不使用数据读取器使用数据集。

我已经尝试了很多方法将数据从数据库转换为窗体到图片框。我想根据组合框中选择的项目将图像放在图片框中。我也遇到了根据在组合框中选择DB中的项目将其他值加载到文本字符串中的问题;看代码。代码有很多图像从SQLite db到图片框。



我尝试过:



 #RegionData Test

Dim aidlink As String

Const CONNECTION_STR 作为 字符串 = 数据源= a2w;版本= 3;

私有 Sub ReadData()

Dim objConn < span class =code-keyword> As SQLiteConnection
Dim objCommand As SQLiteCommand
Dim objReader As SQLiteDataReader

尝试

objConn = SQLiteConnection(CONNECTION_STR)
objConn.Open()

objCommand = objConn.CreateCommand()
objCommand.CommandText = < span class =code-string> SELECT [id],[aname],[fname],[slink],[aimg]来自[apps] ORDER BY aname ' SELECT * FROM apps ORDER BY aname

objReader = objCommand.ExecuteReader()

ComboBox1.Items.Clear()
while (objReader.Read())
ComboBox1.Items.Add(objReader( aname))

Dim bytaimg(objReader.GetBytes( 1 , 0 没什么 0 整数 .MaxValue) - 1 作为 字节 ' 返回错误指定的强制转换无效
objReader.GetBytes( 1 0 ,bytaimg, 0 ,bytaimg.Length)
Dim stmaimg As MemoryStream(bytaimg)
PictureBox1.Image = Image.FromStream(stmaimg)
PictureBox2.Image = CType ((objReader( aimg )),图片)




Dim aid =( steam:// rungameid /& (objReader( slink)))' ,String)
aidlink = aid
Dim tid =(objReader( slink))

.Text = CType (Application.ProductName& & v& Application.ProductVersion& & 应用ID:& & tid ,字符串

结束

Catch ex < span class =code-keyword> As 异常
MessageBox.Show( 错误已经发生:& ex.Message)

最后

如果 IsNothing(objConn)然后
objConn.Close()
结束 如果
结束 尝试
objConn.Close()
结束 Sub

#End Region

解决方案

请参阅 SqliteDataReader.GetBytes方法 [ ^ ]。

Hi all I have been trying to add some DB functionality to one of my apps and not having much luck. Please keep in mind not using Data set using Data reader.
I have tried many ways to get my data from db to windows form into the picture box. I want the image to be placed in picture box based on what item is chosen in combo box. I am also having issues with loading other values into text strings based on what item in the DB is selected in the Combo box; see code. The code has many attempts of image from SQLite db to picture box.

What I have tried:

#Region "Data Test"
 
    Dim aidlink As String

    Const CONNECTION_STR As String = "Data Source=a2w;Version=3;"

    Private Sub ReadData()

        Dim objConn As SQLiteConnection
        Dim objCommand As SQLiteCommand
        Dim objReader As SQLiteDataReader

        Try

            objConn = New SQLiteConnection(CONNECTION_STR)
            objConn.Open()

            objCommand = objConn.CreateCommand()
            objCommand.CommandText = "SELECT [id],[aname] ,[fname] ,[slink] ,[aimg] From [apps] ORDER BY aname" ' "SELECT * FROM apps ORDER BY aname" 

            objReader = objCommand.ExecuteReader()

            ComboBox1.Items.Clear()
            While (objReader.Read())
                ComboBox1.Items.Add(objReader("aname"))

                Dim bytaimg(objReader.GetBytes(1, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte 'returns error "Specified cast is not valid"
                objReader.GetBytes(1, 0, bytaimg, 0, bytaimg.Length)
                Dim stmaimg As New MemoryStream(bytaimg)
                PictureBox1.Image = Image.FromStream(stmaimg)
                PictureBox2.Image = CType((objReader("aimg")), Image)




                Dim aid = ("steam://rungameid/" & (objReader("slink"))) ', String)
                aidlink = aid
                Dim tid = (objReader("slink"))

                Me.Text = CType(Application.ProductName & " " & "v" & Application.ProductVersion & " " & "App ID:" & " " & tid, String)

            End While

        Catch ex As Exception
            MessageBox.Show("An error has occurred: " & ex.Message)

        Finally

            If Not IsNothing(objConn) Then
                objConn.Close()
            End If
        End Try
        objConn.Close()
    End Sub

#End Region

解决方案

See SqliteDataReader.GetBytes Method[^].


这篇关于Vb.net VIS2017和sqlite图像从DB到带有数据读取器的图片框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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