2017-05-17 9 views
0

こんにちは皆、私はVBフォームを使用してログインしようとしていますが、毎回ログアウトしようとしました。ストアドプロシージャと変数の値とすべてが大丈夫だと思われる。ストアドプロシージャを使用してログインできませんVB .net

私が行方不明です何を知らない...ログイン機能アイブがカウント値をチェックし、それが-1を返すに:いくつかの助け

が、これはこれは、ログインボタン

Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click 
    If txtUser.Text = "" And txtPassword.Text = "" Then 
     MsgBox("Fields are empty") 
    Else 
     If txtUser.Text = "" Then 
      MsgBox("User is empty") 
     Else 
      If txtPassword.Text = "" Then 
       MsgBox("Password is empty") 
      Else 
       Dim dts As New cPerson 
       dts.user = txtUser.Text 
       dts.pass = txtPassword.Text 
       If Login(dts) = True Then 
        Me.Hide() 
        Dim box = New Menu() 
        box.Show() 
       Else 
        MsgBox("user/password is wrong") 
       End If 
      End If 
     End If 
    End If 
End Sub 

です/くださいログイン機能

Public Shared Function Login(ByVal dts As cPerson) As Boolean 
    Try 
     conexion.Open() 
     comando = New SqlCommand("SP_Login") 
     comando.CommandType = CommandType.StoredProcedure 
     comando.Connection = conexion 
     comando.Parameters.AddWithValue("@usu", dts.user) 
     comando.Parameters.AddWithValue("@pas", dts.pass) 
     Dim cont As Integer = comando.ExecuteNonQuery() 
     If (cont > 0) Then 
      Return True 
     Else 
      Return False 
     End If 
    Catch ex As Exception 
     MsgBox(ex.Message) 
     Return False 
    Finally 
     conexion.Close() 
    End Try 
End Function 

、最終的にはSP

GO 
CREATE PROCEDURE SP_Login 
@usu as varchar(15), 
@pas as varchar(20) 
as 
select * from Person where [email protected] and [email protected] 
+0

私の提案は、SP 'SP_Login' getはテーブル' Person'の行数を返すべきです。 'ExecuteScalar'を使います。パスワードとユーザー名をできるだけネットワークに渡すのは避けてください。 –

答えて

0

ExecuteNonQueryを呼び出してクエリを実行すると、問題が発生する可能性がありますか?非問合せとは、レコードを取得しない1つ以上のSQL文です。あなたのSQLは何をしていますか?レコードを取得します。 ExecuteReaderを呼び出してからHasRowsプロパティをテストして、一致するかどうかを判断する必要があります。または、カウントを返すようにsprocを変更し、ExecuteScalarに電話してそのカウントを取得してください。

関連する問題