Hi sarabeach,
Please refer below sample.
SQL
CREATE TABLE [UserLogin]
(
[UserName] VARCHAR(20)
,[Password] VARCHAR(20)
)
GO
INSERT INTO [UserLogin] VALUES('MudassarKhan', '1234')
GO
CREATE PROCEDURE [LoginPage]
@Username VARCHAR(20)
,@Password VARCHAR(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT COUNT(*)
FROM [UserLogin]
WHERE [Username] = @Username
AND [Password] = @Password
END
Controller
Public Class HomeController
Inherits Controller
' GET: Home
Function Index() As ActionResult
Return View()
End Function
<HttpPost>
Function Index(username As String, password As String) As ActionResult
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("LoginPage", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Username", username)
cmd.Parameters.AddWithValue("@Password", password)
con.Open()
Dim result As Integer = Convert.ToInt32(cmd.ExecuteScalar())
If (result > 0) Then
Return RedirectToAction("Home")
End If
con.Close()
End Using
End Using
Return View()
End Function
Function Home() As ActionResult
Return View()
End Function
End Class
View
@Code
Layout = Nothing
End Code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@Using Html.BeginForm("Index", "Home", FormMethod.Post)
@<input type="text" name="username" />
@<input type="password" name="password" />
@<input type="submit" value="Login" />
End Using
</body>
</html>
Screenshot
