Conversion of function VB into VB.NET

5 pts.
Tags:
Source code
VB
VB migration
VB.NET
Visual Basic
How can I convert below VB function into VB.NET?
Public Function FChkUserLoggedIn(LoginId As Long) As Boolean
Dim rs As ADODB.RecordSet, strsql As String
Set rs = New ADODB.RecordSet
'strSql = "select msession from log where msession in (select msession from log where loginid = " & LoginId & " and form = 'menu' and active) and msession not in (select msession from log where loginid = " & LoginId & " and form = 'menu' and not active)"
strsql = "select * from log where form='menu' and active and loginid = " & LoginId
If rs.State = 1 Then rs.Close
rs.open strsql, cnComp, adOpenStatic, adLockReadOnly
If rs.EOF Then
FChkUserLoggedIn = False
Else
FChkUserLoggedIn = True
End If
If rs.State = 1 Then rs.Close
Set rs = Nothing
End Function

Answer Wiki

Thanks. We'll let you know when a new response is added.

This should do the trick:

Public Function FChkUserLoggedIn(ByRef LoginId As Integer) As Boolean
Dim result As Boolean = False
Dim cnComp As SqlConnection 'Don't forget to configure the connection!!
Dim rs As New DataSet
'strSql = "select msession from log where msession in (select msession from log where loginid = " & LoginId & " and form = 'menu' and active) and msession not in (select msession from log where loginid = " & LoginId & " and form = 'menu' and not active)"
Dim strsql As String = "select * from log where form='menu' and active and loginid = " & LoginId
'Since we are now using DataSets, the following line doesn't really make sense anymore:
'If rs.State = 1 Then rs.Close
Dim com As SqlCommand = New SqlCommand()
com.Connection = cnComp 'Need to add the Connection
com.CommandText = strsql
Dim adap As SqlDataAdapter = New SqlDataAdapter(com.CommandText, com.Connection)
rs = New DataSet("dsl")
adap.Fill(rs)
result = Not (rs.Tables(0).Rows.Count = 0)
'Since we are now using DataSets, the following line doesn't really make sense anymore:
'If rs.State = 1 Then rs.Close
Return result
End Function

Hope this answers your question. :)
BTW, so you know, I migrated the code using the Visual Basic Upgrade Companion. I performed some small manual changes, specially regarding the rs.State line, but other than that (and the comments), this is the code as it comes out of the tool. It shows one of the features of the VBUC, which is the capability to do ADO to ADO.NET migration.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following