0

i got runtime error when is send register form: My code:

If IsPostBack Then

    Dim errorText As String = ""
    Dim formName As String = "register"
    Dim _username As String = MyUtils.setme(username.Text)
    Dim _fname As String = MyUtils.setme(fname.Text)
    Dim _password As String = MyUtils.setme(password.Text)
    Dim _tel As String = MyUtils.setme(tel.Text)
    Dim _street As String = MyUtils.setme(street.Text)
    Dim _street_no As String = MyUtils.setme(street_no.Text)
    Dim _city As String = MyUtils.setme(city.Text)

    Dim ds As New DataSet
    ds = MyUtils.runMSSQL_DS("select num from buyers where username='" & _username & "'")

    If MyUtils.isSpam(formName) Then
        errorText = "test1"
    ElseIf _fname = "" Then
        errorText = "test2"
    ElseIf _tel.Length < 7 Or _tel.Length > 11 Then
        errorText = "test3"
    ElseIf MyUtils.checkEmail(_username) = False Then
        errorText = "test4"
    ElseIf _password.Length < 4 Then
        errorText = "test5"
    Else
        If ds.Tables(0).Rows.Count > 0 Then
            errorText = "test6"
        End If
    End If
End If

I got error: System.NullReferenceException on line errorText = "test2"

what i need to do?

*edit: not its not duplicate because its Specific code that i got this error, i read before what is it NullReferenceException and all the answers dont helped me.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
gregory
  • 233
  • 5
  • 14
  • Are you certain it was on that line? I can't think of a reason that setting a string variable to "test2" would cause that issue. It's more likely that one of the 'MyUtils' functions isn't behaving correctly. – phillyd Aug 04 '16 at 10:57
  • 1
    @MattWilko is telling you that the answers *do* help you, you just need to take the time to understand them. – Jonathan Mee Aug 04 '16 at 12:35
  • Hint: Try changing `ElseIf _fname = "" Then` to `ElseIf String.IsNullOrEmpty(_fname) Then` – Matt Wilko Aug 04 '16 at 12:36

0 Answers0