关于一句代码的错误!很急大家来帮忙!
以下是我的下一张图片按钮的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
(1) If currentpos = dsPictures.Tables("0").Rows.Count - 1 Then
Return
Else
currentpos += 1
Dim arrPicture() As Byte = _
CType(dsPictures.Tables(0).Rows(currentpos)("Picture"), _
Byte())
Dim ms As New MemoryStream(arrPicture)
With PictureBox1
.Image = Image.FromStream(ms)
End With
End If
End Sub
运行到第一句的时候出现:未处理的“System.NullReferenceException”类型的异常出现在 gongcheng.exe 中
其他信息:未将对象引用设置到对象的实例。的错误提示
大家帮忙看看怎么改?!!急呀就这一句!以下是我from_load的程序:
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim isConnecting As Boolean = True
While isConnecting
Try
Dim northwindConnection As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("SELECT * " & _
"FROM Picture", _
northwindConnection)
da = New SqlDataAdapter(cmd)
cbd = New SqlCommandBuilder(da)
dsPictures = New DataSet()
da.Fill(dsPictures)
isConnecting = False
didPreviouslyConnect = True
Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit While
Catch exc As Exception
If connectionString = SQL_CONNECTION_STRING Then
' Couldn't connect to SQL Server. Now try MSDE.
connectionString = MSDE_CONNECTION_STRING
' frmStatusMessage.Show("Connecting to MSDE")
Else
' Unable to connect to SQL Server or MSDE
' frmStatusMessage.Close()
MessageBox.Show(CONNECTION_ERROR_MSG, _
"Connection Failed!", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End Try
End While
Dim arrPicture() As Byte = _
CType(dsPictures.Tables(0).Rows(0)("Picture"), _
Byte())
Dim ms As New MemoryStream(arrPicture)
With PictureBox1
.Image = Image.FromStream(ms)
.SizeMode = PictureBoxSizeMode.CenterImage
.BorderStyle = BorderStyle.Fixed3D
End With
End Sub
以上运行正常