警告1变量“dr”在赋值前被使用。可能会在运行时导致空引用异常。 请高手指教!!
代码如下:DimstrsqlAsStringDimconnAsNewconstr.dbstrsql="select*fromstuloginfowherestuid='"...
代码如下:
Dim strsql As String
Dim conn As New constr.db
strsql = "select * from stuloginfo where stuid='" & Textbox1.Text & " 'and stupassword='" & TextBox2.Text & " ' "
Dim myconn As New SqlConnection(constr.db.getstr)
Dim mycommand As New SqlCommand(strsql, myconn)
Session("stuno") = Textbox1.Text
Dim dr As SqlDataReader
Try
myconn.Open()
dr = mycommand.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read()
If Trim(dr.Item(3)) = "1111" Then
Response.Redirect("stulogin.aspx")
Else
Response.Redirect("student.aspx")
End If
End While
Catch ex As SqlException
Label1.Text = ex.Message
Finally
dr.Close()--------------------------------dr画了绿线
myconn.Close()
mycommand.Dispose()
End Try 展开
Dim strsql As String
Dim conn As New constr.db
strsql = "select * from stuloginfo where stuid='" & Textbox1.Text & " 'and stupassword='" & TextBox2.Text & " ' "
Dim myconn As New SqlConnection(constr.db.getstr)
Dim mycommand As New SqlCommand(strsql, myconn)
Session("stuno") = Textbox1.Text
Dim dr As SqlDataReader
Try
myconn.Open()
dr = mycommand.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read()
If Trim(dr.Item(3)) = "1111" Then
Response.Redirect("stulogin.aspx")
Else
Response.Redirect("student.aspx")
End If
End While
Catch ex As SqlException
Label1.Text = ex.Message
Finally
dr.Close()--------------------------------dr画了绿线
myconn.Close()
mycommand.Dispose()
End Try 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询