Thanks. I did what you said.
Code:
sub verifyLogin (Source as Object, e as EventArgs)
Dim objCon As New OleDBConnection(connectionString)
Dim objCon1 as new OleDbConnection(connectionString)
Dim objCommand as OleDbCommand
Dim objCommand1 as OleDbCommand
Dim objDataReader as OleDBDataReader
Dim objDataReader1 as OleDbDataReader
Dim StrSQL, StrSQL1, strSQL2 as String
Dim dbcomm, dbread
dim lastlogins as datetime
strSQL = "select emp_no from Employee where status = 'active' or status = 'inactivated' " _
& "; select course_id, course_name from course; select emp_no from Employee;"
objCon.Open()
objCommand = new OLEDBCommand (strSQL, objCon)
objDataReader = objCommand.ExecuteReader()
Dim validUser
validUser = false
While objDataReader.Read()
if txtEmpID.Text = objDataReader.GetString(0) then
validUser = true
Session("userSession") = objDataReader.Getvalue(0).toString()
strSQL2 = "select max(login_time) from emp_login where emp_no = " _
& "'"& Session("userSession") &"'"
objCon1.open()
dbcomm = new OleDbCommand(strSQL2, objCon1)
dbread = dbcomm.executeReader()
dbread.read()
Session("lastlogin") = dbread.getvalue(0)
if ((Session("lastlogin"))is DBNull.Value ) then
Session("lastloginDate") = ""
else
lastlogins = convert.toDateTime(Session("lastlogin"))
Session("lastloginDate") = lastlogins.toString("d")
end if
dbread.close()
objCon1.close()
Session("loginTime") = datetime.now().toString("T")
Session("loginDate") = datetime.now().toString("d")
Session("loginData") = datetime.now().toString()
objDataReader.NextResult()
while objDataReader.Read()
if portalList.SelectedItem.value = objDataReader.GetString(1) then
Session("course_id") = objDataReader.GetString(0)
end if
end while
strSQL1 = "insert into Emp_Login (Emp_No, Login_time, logout_time) " _
& "values ('"& Session("userSession") &"', '"& Session("loginData") &"', '')"
objCon1.open()
objCommand1 = new OLEDBCommand (strSQL1, objCon1)
objDataReader1 = objCommand1.ExecuteReader(CommandBehavior.Closeconnection)
objDataReader1.Close()
objCon1.Close()
Server.transfer("EHomePage.aspx")
end if
if not validUser then
objDataReader.NextResult()
while objDataReader.Read()
if txtEmpID.Text = objDataReader.GetString(0) then
errorTxt.Text = "Your status is inactive! Please contact system administrator"
txtEmpId.Text= ""
else
errorTxt.text = "Invalid Login! Please try again or contact system administrator"
txtEmpId.Text= ""
end if
end while
end if
end while
objDataReader.Close()
objCon.Close()
end sub
Now I get this error
Server Error in '/ELearning' Application.
--------------------------------------------------------------------------------
The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable.
Source Error:
Line 108: while objDataReader.Read()
Line 109:
Line 110: if txtEmpID.Text = objDataReader.GetString(0) then Line 111: errorTxt.Text = "Your status is inactive! Please contact system administrator"
Line 112: txtEmpId.Text= ""
Source File: c:\inetpub\wwwroot\ELearning\ELogin.aspx Line: 110
Stack Trace:
[InvalidCastException: The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable.]
System.Data.OleDb.DBBindings.get_ValueString()
System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
ASP.ELogin_aspx.verifyLogin(Object Source, EventArgs e) in c:\inetpub\wwwroot\ELearning\ELogin.aspx:110
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
I also tried to make the .getString(0) to .getValue(0).toString()
but then I get the wrong error message. I have two error messages. I am supposed to get the first one
(see above code) if there is a value in the database but instead I am getting the second one.
Please inform me if I there are any doubts. Your help is greatly appreciated.