我真的不知道怎么办了

rlc19851203 2007-04-19 02:40:21
Public Class formdenglu
Inherits System.Windows.Forms.Form
Private Function ExecuteSQL(ByVal SQL As String) As String
Dim con As New SqlConnection("Server=.;Integrated Security=SSPI;Database=Marcket")
Dim command As New SqlCommand
command.Connection = con
command.CommandText = SQL
Try
con.Open()
Dim str As String = command.ExecuteScalar()
Return str
Catch ex As Exception
MsgBox(ex.ToString)
Finally
con.Close()
End Try
Return Nothing
End Function

出现错误:

未处理的“System.NullReferenceException”类型的异常出现在 登陆界面.exe 中。

其他信息: 未将对象引用设置到对象的实例。
...全文
304 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
踏平扶桑 2007-04-21
  • 打赏
  • 举报
回复
连SQL要用户名和密码的吧?
我看你连接字符串里没有写用户名和密码啊
amandag 2007-04-21
  • 打赏
  • 举报
回复
1. 错误出现在那一行
2. 最好能设置断点跟踪一下
hzybc 2007-04-21
  • 打赏
  • 举报
回复
command.CommandText = SQL
SQL 是空值
leixueqiyi 2007-04-19
  • 打赏
  • 举报
回复
Command.ExecuteScale().toString()
有时ExecuteScale() 返回 NULL,则可以通过 catch (NullReferenceException) 编写相应的代码。
SQL参数看看是不是正确
stonepeter 2007-04-19
  • 打赏
  • 举报
回复
都有可能出错呢。
SQL参数进来的时候你没有检查,可能是空串。
Finally
con.Close() '这里是不是要检查一下con是否为空呢?
最好能debug一下。
Red_angelX 2007-04-19
  • 打赏
  • 举报
回复
NullReferenceException
shuimuyi 2007-04-19
  • 打赏
  • 举报
回复
SQL 语句在什么地方呢?
magicbacon 2007-04-19
  • 打赏
  • 举报
回复
错误指向那一行?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧