How to use DataReader to retrive data from the database

Discussion in 'ASP .Net' started by Goran, Nov 21, 2005.

  1. Goran

    Goran Guest

    I'm a student and I've just started to learn Visual Studio.NET. I have
    a project to make a web application.
    I have a problem to connect to the database and retriving the PassType
    of the tblEmployee.

    First I create Bussines Object user.vb and I declare in it:

    Public Class EmployeeDetails
    Public EmpIdNo As Integer
    Public Name As String
    Public Pass As String
    Public PassType As String
    Public Mobile As String
    Public Email As String
    Public Jobposition As String
    Public Section As String
    Public Group As String
    Public Other As String

    End Class

    After I need to have a function for getting the employee details that
    are already in the Database.

    Public Class Employee
    Private objConn As New OleDbConnection("Provider=SQLOLEDB.1;" &
    _
    "Password=test;Persist Security Info=True;User ID=test;" & _
    "Initial Catalog=CC_3;Data Source=05PCSTUDENT1")

    Public Function GetEmpDetails(ByVal EmpIDNo As Integer) As
    EmployeeDetails

    Dim objCmd As New OleDbCommand( _
    "SELECT * FROM tblEmployee" & _
    "WHERE tblEmployee.Name = @Name AND tblEmployee.Pass =
    @Pass", objConn)

    Dim objReader As OleDbDataReader
    Try
    objConn.Open()
    objReader = objCmd.ExecuteReader
    Catch e As OleDbException
    Throw e
    End Try

    Dim objDetails As New EmployeeDetails
    While objReader.Read
    With objDetails
    .EmpIdNo = objReader.GetFloat(0)
    .Name = objReader.GetString(1)
    .Pass = objReader.GetString(2)
    .PassType = objReader.GetString(3)
    .Mobile = objReader.GetString(4)
    .Email = objReader.GetString(5)
    .Jobposition = objReader.GetString(6)
    .Section = objReader.GetString(7)
    .Group = objReader.GetString(8)
    .Other = objReader.GetString(9)
    End With
    End While
    objReader.Close()

    Return objDetails

    End Function
    end class

    So from here I need the PassType so that on login I can compare the
    Name, Password and Password Type.
    I have a login.aspx page for this application. What should I write in
    it so that I can retrive the PassType information from the DataBase
    that I can after compare and eventualy to login.

    Probably I have lots of mistakes but I'm a starter so I don't yet know
    the whole syntax.

    Thanx,
    Goran
    Goran, Nov 21, 2005
    #1
    1. Advertising

  2. Goran

    Mark Rae Guest

    "Goran" <> wrote in message
    news:...

    > Private objConn As New OleDbConnection("Provider=SQLOLEDB.1;" &


    Firstly, why are you using OleDb to connect to SQL Server instead of the
    native .NET data provider?

    > Dim objCmd As New OleDbCommand( _
    > "SELECT * FROM tblEmployee" & _
    > "WHERE tblEmployee.Name = @Name AND tblEmployee.Pass =
    > @Pass", objConn)


    Secondly, try to get into the habit of using stored procedures instead of
    dynamic SQL. In this case, are "@Name" and "@Pass" VB.NET variables? If not,
    I can't see how this SQL is ever going to work...

    Is your DataReader object actually being populated with data?

    > So from here I need the PassType so that on login I can compare the
    > Name, Password and Password Type.
    > I have a login.aspx page for this application. What should I write in
    > it so that I can retrive the PassType information from the DataBase
    > that I can after compare and eventualy to login.


    Well, you could store the PassType in a Session variable; you could pass it
    to the login.aspx page as a QueryString variable, or you could fetch it out
    of the database in the Page_Load event of the login.aspx page.
    Mark Rae, Nov 21, 2005
    #2
    1. Advertising

  3. Goran

    Goran Guest

    OK, I've made a stored procedure for getting all the Employee
    information.
    But still I don't know what to write in login.aspx to retrive the
    PassType value with the DataReader and then to compare it?
    I have declared a variable pType as string. I need to store the
    PassType value in it so that I can compare it. What should I write?
    Can you please write me some example?

    Thank you for the previous reply.
    Goran, Nov 21, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Dong
    Replies:
    0
    Views:
    459
    Tony Dong
    Dec 20, 2005
  2. vijay
    Replies:
    2
    Views:
    3,371
    vijaya kumar.P
    Aug 29, 2003
  3. Craig Deelsnyder
    Replies:
    1
    Views:
    390
    Craig Deelsnyder
    Mar 7, 2005
  4. Santosh

    Retrive data from session variables

    Santosh, Jul 14, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,658
    Hans Kesting
    Jul 14, 2006
  5. =?Utf-8?B?UGV0ZXIgSiwgU2Nhbmlh?=

    Retrive data from an client side Excel source

    =?Utf-8?B?UGV0ZXIgSiwgU2Nhbmlh?=, Mar 30, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    447
    Mark Rae
    Mar 30, 2007
Loading...

Share This Page