读书人

小弟我真的不知道怎么处理了

发布时间: 2012-02-02 23:57:14 作者: rapoo

我真的不知道怎么办了
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 中。

其他信息: 未将对象引用设置到对象的实例。

[解决办法]
Command.ExecuteScale().toString()
有时ExecuteScale() 返回 NULL,则可以通过 catch (NullReferenceException) 编写相应的代码。
SQL参数看看是不是正确
[解决办法]
command.CommandText = SQL
SQL 是空值

读书人网 >VB Dotnet

热点推荐