473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to use DataReader to retrive data from the database

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

Nov 21 '05 #1
2 2127
"Goran" <go**************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.
Nov 21 '05 #2
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.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
4
by: Maziar Aflatoun | last post by:
Hi everyone, I am working on the 'Delete' section of my program. What I need to do is query my database and for every ID that it finds I want to remove a file+ID.jpg from my file folder and...
14
by: Bihn | last post by:
I was reading about datareader which is said to be slimmer & faster then dataset. Since the datareader have to go fetching the dat from the database every time it need it, the data it gets then...
2
by: Shapper | last post by:
Hello, I want to retrive N records from a database (I am using SQL and Access in 2 different projects): id class text 1 book book comments 2 paper paper comments ....
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.