Thursday, March 29, 2012

please convert this classic asp to asp.net

would anyone be willing to convert this classic asp/vbscript/ado to asp.net/vb.net/ado.net? I want to learn how to set Session("userId") using the absolute simplest techniques in asp.net. Thanks in advance.


Dim myConnection
Dim myConnectionStr
Dim myRecordSet
Dim mySQL

Set myConnection = Server.CreateObject("ADODB.Connection")
myConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dataStores\webDbs\webLogin.mdb;"
myConnection.Open myConnectionStr

Set myRecordSet = Server.CreateObject("ADODB.RecordSet")
mySQL = "SELECT tblUsers.userId FROM tblUsers WHERE (((tblUsers.emailAddress)='test@dotnet.itags.org.yahoo.com'));"
myRecordSet.Open mySQL, myConnection

If Not myRecordSet.EOF Then
Session("userId") = myRecordSet("userId")
End If

myRecordSet.Close
Set myRecordSet = Nothing
myConnection.Close
Set myConnection = Nothing

NOTE: Moderator fixed <Code> tags...Hi,

instead of a recordset you can use asqldatareader instead.

Alsoview forum 132.

Grz, Kris.


Sub Page_Load(s As Object, e As EventArgs)
lblResult.Text = getUserId()
End Sub

Function getUserId() As String
Dim myConnection As OleDbConnection
Dim myConnectionStr As String
Dim myCommand As OleDbCommand
Dim myDataReader As OleDbDataReader
Dim mySQL As String

myConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Datastores\LCS_Web\BoardElect.mdb;"
myConnection = New OleDbConnection(myConnectionStr)

mySQL = "SELECT tblUsers.userId FROM tblUsers WHERE (((tblUsers.emailAddress)='test@.yahoo.com'));"
myCommand = New OleDbCommand(mySQL, myConnection)
myConnection.Open()
myDataReader = myCommand.ExecuteReader()

myDataReader.Read()
getUserId = myDataReader.GetValue(0)

myDataReader.Close()
myConnection.Close()
End Function

got it from another forum, but thanks
Does this help ?

PopUpWindow 1.1

regards
that's a very nice component you've written, but is there some correlation to the topic at hand?

0 comments:

Post a Comment