开发者

How best to implement a login system in VB.NET using LINQ to compare information with an Access table? [closed]

开发者 https://www.devze.com 2023-04-09 01:12 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_StackOverflow社区 Closed 11 years ago.

I have been requested to implement a login form into a friend's Visual Basic .NET application. He specifically requested that I should do this using LINQ to compare the input to a table in an Access database. I don't really know why he imposed these restrictions, but who am I to judge?

However, the problem is I am not overly familiar with VB .NET, or LINQ. Could anyone tell me what the most efficient way would be to implement this?

Thank you.


If you Google for tutorials on VB.NET and LINQ, there is lot's of information out there. Your login chec is going to work something like this with VB.Net/LINQ:

' create a re-usable helper function to validate login information
Function Shared ValidateLogin(ByVal username As String, ByVal password as String) _
        As Boolean

    ' create LINQ context to the access database
    Dim ctx As New MyDataContext

    ' check credentials against User table
    Dim usr As User = ctx.Users.SingleOrDefault(Function(u) _
        u.UserName = username AndAlso u.Password = password)

    Return (usr IsNot Nothing)

End Function
  • MyDataContext is a DataContext connected to the Access database. This can be created in Visual Studio by creating New Item -> Datacontext, then using the Server Explorer to connect to your Access database and drag/drop the tables into the DataContext.
  • ctx.Users would be replaced with whatever the name of the User table is in the Access database.
  • u.UserName and u.Password would be replaced with whatever the field names are in your users table for the user's login and password information
  • This function could be called then from your application once you've collected the credentials, and you want to validate them. Then it's up to you to perform the appropriate response logic based on whether the login was successful or not.
0

精彩评论

暂无评论...
验证码 换一张
取 消