System.NullReferenceException:'对象引用未设置为对象的实例。

时间:2019-07-11 17:33:29

标签: vb.net

我是编程新手,我曾尝试创建一个工资单,其中包含一张可以通过数据库检索的图片。

问题是每当我要保存一些new employee informationenter image description here

不放置图片,它将重定向到此错误:

  

2

     

System.Windows.Forms.PictureBox.Image.get返回无。这是一张图片,我想不出如何解决它,因为在给定的示例中没有实例使用图片框

Imports System.IO

Public Class AddNewEmployee
    Dim connection As New SqlConnection("Server = DESKTOP-BBDJH6Q; Database = EmmeSubic; Integrated Security = true")

    Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim command As New SqlCommand("insert into UserDetails(Picture) values ( @Picture)", connection) 'i removed the other things included here to define my question clearly for the picture is my only concern

        Dim pic As New MemoryStream
        ImgBox.Image.Save(pic, ImgBox.Image.RawFormat)

        command.Parameters.Add("@Picture", SqlDbType.Image).Value = pic.ToArray()
    end sub

0 个答案:

没有答案