关于一句代码的错误!很急大家来帮忙!
以下是我的下一张图片按钮的代码:
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
以上运行正常
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
以上运行正常
...全文
相关推荐
11款实用的一句话网站设计代码
11款实用的一句话网站设计代码 11款实用的一句话网站设计代码
Linux: errno: err.h
文件里有提到,在内核的指针里可能有些冗余的信息空间,可以拿过来做特殊处理。比如这里就是通过这个机制,实现了一个返回值的两种可能:传递错误代码,或者正常的指针。/*
将VBS或ASP中的代码转成一句话形式
将VBS或ASP中的代码转成一句话形式 以前都以为直接把换行符换成冒号就可以了...
VBA 一句代码解决On error goto line 多次使用的问题 .txt
一句代码解决On error goto line 多次使用的问题 .txt On error goto line 错误跳转语句只能使用一次 本代码只需要加一句即可重复使用错误跳转 On error goto line VBA错误跳转多次使用的问题 On error goto 0 不行 err.clear也不行
android通过json获取金山词霸每日一句
利用金山词霸开放性api,通过异步处理类访问网络 获取到json,再通过Gson解析json,获取到金山词霸 的每日一句数据.


