本文介绍了显示图片框VB网络的图片路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个带搜索按钮,图片框和文件框的文件图像路径的程序,我想搜索发票编号并在文本框中显示图片和图片路径,但代码不会处理,你能帮我吗?这个代码?? 我尝试过: Private Sub search_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理search.Click command.Connection = con 尝试 str =Select * from datagambar其中NoFaktur = @nofaktur command = New OleDbCommand(str,con) command.Parameters.Add(@ nofaktur,OleDbType.VarChar).Value = nofaktur.Text command .ExecuteNonQuery()调用showimage1() command.Dispose() con.Close() Catch ex As Exception MsgBox(ex.Message)结束尝试结束子 子showimage1() Pictu reBox1.Visible = True PictureBox1.Image = Image.FromFile(G:\ Aplikasi \ Photo \ Faktur Invoice) End Sub INSERT , c> UPDATE 或 DELETE ,不返回任何数据。 要执行 SELECT 查询并读取结果,请使用 ExecuteReader 方法 [ ^ ]。 私人 Sub search_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 search.Click 使用命令作为 新 OleDbCommand ( SELECT * FROM datagambar WHERE NoFaktur = @nofaktur,con) command.Parameters .Add( @ nofaktur,OleDbType.VarChar).Value = nofaktur.Text 尝试 con.Open() 使用 reader As OleDbDataReader = command.ExecuteReader() If reader.Read()然后 Dim 图片路径 As 字符串 = reader.Field( Of 字符串)( 您的图像路径列名) 如果 字符串 .IsNullOrEmpty(imagePath)然后 PictureBox1.Visible = 错误 其他 PictureBox1.Visible = True PictureBox1.Image = Image.FromFile(imagePath) 结束 如果 ...在此处将其他列加载到UI中... 其他 ...不匹配:告诉用户,和清除此处的用户界面.. 。 结束 如果 结束 使用 Catch ex As System.Data.Common.DbException MsgBox(ex.Message) 最后 con.Close() 结束 尝试 结束 使用 结束 子 i have a program with search button, picture box, and textbox for file image path, i want to search invoice number and show the pictures and picture path in textbox but the code won't to process, can you help me with this codes??What I have tried:Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click command.Connection = con Try str = "Select * from datagambar Where NoFaktur = @nofaktur" command = New OleDbCommand(str, con) command.Parameters.Add("@nofaktur", OleDbType.VarChar).Value = nofaktur.Text command.ExecuteNonQuery() Call showimage1() command.Dispose() con.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Sub showimage1() PictureBox1.Visible = True PictureBox1.Image = Image.FromFile("G:\Aplikasi\Photo\Faktur Invoice") End Sub 解决方案 ExecuteNonQuery is for executing commands like INSERT, UPDATE, or DELETE, which don't return any data.To execute a SELECT query and read the results, use the ExecuteReader method[^] instead.Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click Using command As New OleDbCommand("SELECT * FROM datagambar WHERE NoFaktur = @nofaktur", con) command.Parameters.Add("@nofaktur", OleDbType.VarChar).Value = nofaktur.Text Try con.Open() Using reader As OleDbDataReader = command.ExecuteReader() If reader.Read() Then Dim imagePath As String = reader.Field(Of String)("Your image path column name") If String.IsNullOrEmpty(imagePath) Then PictureBox1.Visible = False Else PictureBox1.Visible = True PictureBox1.Image = Image.FromFile(imagePath) End If ... Load other columns into the UI here ... Else ... No match: tell the user, and clear the UI here ... End If End Using Catch ex As System.Data.Common.DbException MsgBox(ex.Message) Finally con.Close() End Try End UsingEnd Sub 这篇关于显示图片框VB网络的图片路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-27 10:04