monkeynote
Newcomer
- Joined
- Nov 17, 2007
- Messages
- 10
hello guys!
i am new to VB.net and i would like to ask if how can i pass sqlparameters in my custom function
i have a class name obj and has a function called search
i am passing the parameter values but it seems that it my username is only the condition that it satisfies (any password will return a value!) am i doing right in passing my parameter collection? username and password must match in the users table.
please help me on how can i fix this bug!
i am new to VB.net and i would like to ask if how can i pass sqlparameters in my custom function
i have a class name obj and has a function called search
Visual Basic:
Public Function Search(ByVal sqlStatement As String, ByVal cparam As SqlParameterCollection, Optional ByRef e As String = "") As String
Try
Dim cm As New SqlCommand
cm.Connection = cn 'Set a Connection
cm.CommandText = sqlStatement 'Execute SQL Statement
cm.Parameters.Add(cparam)
cm.CommandType = CommandType.Text 'Refers that the command is SQL and not Stored Proc
Search = cm.ExecuteScalar() 'Execute the SQL Statement
Catch ex As Exception
e = ex.ToString
Search = "ER"
End Try
End Function
i am passing the parameter values but it seems that it my username is only the condition that it satisfies (any password will return a value!) am i doing right in passing my parameter collection? username and password must match in the users table.
Visual Basic:
Private Sub buttLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttLogIn.Click
Dim sqlStatement As String, UserID As String, err As String = ""
Dim paramcollection As New SqlClient.SqlParameterCollection
Dim param As New SqlClient.SqlParameter
sqlStatement = "SELECT UserID FROM username WHERE username = @username AND password = @password"
param.ParameterName = "@username"
param.Value = boxUsername.Text
paramcollection.Add(param)
param.ParameterName = "@password"
param.Value = boxPassword.Text
paramcollection.Add(param)
UserID = obj.Search(sqlStatement, paramcollection, err)
MsgBox(UserID & " " & err)
If UserID <> "ER" Then
Me.Close()
End If
End Sub
please help me on how can i fix this bug!