你调用的对象是空的。 vb.net图片框保存错误

时间:2017-11-11 02:38:56

标签: sql-server vb.net picturebox

我有LMS书在VB.Net中添加表格。它包含图片框和文本框,当我单击保存按钮时,它显示“对象引用未设置为对象的实例”错误消息。在顶部,我还包括以下内容。

Option Strict On
Option Explicit On

保存按钮编码为:

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim ms As New MemoryStream()
    picPhoto.Image.Save(ms, picPhoto.Image.RawFormat)
    Dim data As Byte() = ms.GetBuffer()
    Dim p As New SqlParameter("@photo", SqlDbType.Image)
    p.Value = data
    cmd.Parameters.Add(p)

    sql = "INSERT INTO tblBookDetail (accessionNo, authorId, title, pages, price, ISBN, noOfCopies, pubId, classId, source, bookShelfNo, bookEdition, bookCoverImg) VALUES (@accNo, @auID, @title, @pages, @price, @ISBN, @noOfCopies, @pubID, @classID, @src, @shlfNo, @edition, @img)"
    con.Open()
    cmd = New SqlCommand(sql, con)

    cmd.Parameters.Add("@accNo", SqlDbType.Int).Value = txtBookID.Text
    cmd.Parameters.Add("@auID", SqlDbType.Int).Value = cmbAuthor.Text
    cmd.Parameters.Add("@title", SqlDbType.VarChar).Value = txtEdition.Text
    cmd.Parameters.Add("@pages", SqlDbType.Int).Value = txtPageNo.Text
    cmd.Parameters.Add("@price", SqlDbType.Decimal).Value = txtPrice.Text
    cmd.Parameters.Add("@ISBN", SqlDbType.Int).Value = txtISBN.Text
    cmd.Parameters.Add("@noOfCopies", SqlDbType.Int).Value = txtNoOfCopies.Text
    cmd.Parameters.Add("@pubID", SqlDbType.Int).Value = cmbPub.Text
    cmd.Parameters.Add("@classID", SqlDbType.Int).Value = cmbClass.Text
    cmd.Parameters.Add("@src", SqlDbType.VarChar).Value = cmbSrc.Text
    cmd.Parameters.Add("@shlfNo", SqlDbType.Int).Value = cmbBookShelf.Text
    cmd.Parameters.Add("@edition", SqlDbType.Int).Value = txtEdition.Text

    cmd.Parameters.Add("@img", SqlDbType.Image).Value = picPhoto.Image

    cmd.ExecuteNonQuery()

    MsgBox("SUCCESS")
    con.Close()

End sub

0 个答案:

没有答案