• 全部
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
  • 问答

关于一句代码的错误!很急大家来帮忙!

bluesanke 2004-03-26 05:19:35
以下是我的下一张图片按钮的代码:
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
以上运行正常
...全文
9 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
accpzj 2004-03-29
If currentpos = dsPictures.Tables("0").Rows.Count - 1 Then
要改为If currentpos = dsPictures.Tables(0).Rows.Count - 1 Then
回复
bluesanke 2004-03-29
Public Class Form3
Inherits System.Windows.Forms.Form
Protected dsPictures As DataSet
这里定义的大家帮忙看
回复
ALong_Yue 2004-03-26
dsPictures 定义在哪里?
回复
相关推荐
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2004-03-26 05:19
社区公告
暂无公告