473,666 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=SQLO LEDB.1;" &
_
"Password=test; Persist Security Info=True;User ID=test;" & _
"Initial Catalog=CC_3;Da ta Source=05PCSTUD ENT1")

Public Function GetEmpDetails(B yVal EmpIDNo As Integer) As
EmployeeDetails

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

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

Dim objDetails As New EmployeeDetails
While objReader.Read
With objDetails
.EmpIdNo = objReader.GetFl oat(0)
.Name = objReader.GetSt ring(1)
.Pass = objReader.GetSt ring(2)
.PassType = objReader.GetSt ring(3)
.Mobile = objReader.GetSt ring(4)
.Email = objReader.GetSt ring(5)
.Jobposition = objReader.GetSt ring(6)
.Section = objReader.GetSt ring(7)
.Group = objReader.GetSt ring(8)
.Other = objReader.GetSt ring(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 2136
"Goran" <go************ **@gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Private objConn As New OleDbConnection ("Provider=SQLO LEDB.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.Nam e = @Name AND tblEmployee.Pas s =
@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
363
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 in ADO.NET in MSDN and there is a confusion regarding the buffering of data in case of DATAREADER. The link for MSDN JAN 2004 is -
6
750
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 object 1. DataReader dr = cmd.executereader(); 2.while(dr.read()) { // do something //} I have a break point in line 2. when i run my application and once it hits the break point (i.e line 2) I opened query analyzer and deleted all the rows in...
20
5524
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 "clean up" the DataView once it is not referenced and will not effect the number of connections to the database. A DataReader on the other hand always maintains a connection to the database and must be explicitly closed (Do not rely on garbage...
4
3052
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 update another table with that information. However, I'm getting the following error message. There is already an open DataReader associated with this Connection which must be closed first. Description: An unhandled exception occurred during the...
14
2233
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 should be up to date. However, both the IbuySpy and Duwamish samples and most, if not all, the shopping cart sample codes I've seen use dataset to implement the opration for ecommerce sites. So is the trip that the datareader need to go fetch the...
2
990
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
2903
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 returns N rows. DataReader object? Collection object? DataTable object? Returning a DataReader object is not a good practice...right? Thnks for all your suggestions!!
10
6097
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 code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed first' Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As
1
2982
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 image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
0
8448
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.