473,409 Members | 1,985 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,409 software developers and data experts.

Reader not reading

I've got the following code in a control and the reader doesn't seem to be
working. The connection details are correct.

Any ideas? I am reading data from this database to log the user and a lot of
the details are the same.

public class AdminNavigation : System.Web.UI.UserControl

{

protected System.Web.UI.WebControls.HyperLink hypProducts;

protected System.Web.UI.WebControls.Label lblDiv1;

protected System.Web.UI.WebControls.HyperLink hypOrders;

protected System.Web.UI.WebControls.Label lblDiv2;

protected System.Web.UI.WebControls.HyperLink hypSales;

protected System.Web.UI.WebControls.Label lblDiv3;

protected System.Web.UI.WebControls.HyperLink hypReviews;

protected System.Web.UI.WebControls.Label lblDiv4;

protected System.Web.UI.WebControls.HyperLink hypEmail;

protected System.Web.UI.WebControls.Label lblDiv5;

protected System.Web.UI.WebControls.HyperLink hypUsers;

protected System.Web.UI.WebControls.Label lblDiv6;

protected System.Web.UI.WebControls.HyperLink hypAdmin;

private void Page_Load(object sender, System.EventArgs e)

{

if (!Context.User.Identity.IsAuthenticated)

{

this.hypProducts.Visible = false;

this.hypOrders.Visible = false;

this.hypSales.Visible = false;

this.hypReviews.Visible = false;

this.hypEmail.Visible = false;

this.hypUsers.Visible = false;

this.hypAdmin.Visible = false;

this.lblDiv1.Visible = false;

this.lblDiv2.Visible = false;

this.lblDiv3.Visible = false;

this.lblDiv4.Visible = false;

this.lblDiv5.Visible = false;

this.lblDiv6.Visible = false;

}

SqlConnection con;

string sql;

SqlCommand cmd;

SqlDataReader AddAdminreader;

con = new SqlConnection("data source=127.0.0.1; initial
catalog=ConsoleJunkies; user id=****; password=****");

sql = "SELECT AddAdmin FROM [Admin] WHERE AdminID='" +
Context.User.Identity.Name.ToString() + "'";

cmd = new SqlCommand(sql, con);

con.Open();

AddAdminreader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

if (AddAdminreader.Read())

{

if (AddAdminreader["AddAdmin"].ToString()=="1")

{

//Allowed full admin

this.hypProducts.Visible = true;

this.hypOrders.Visible = true;

this.hypSales.Visible = true;

this.hypReviews.Visible = true;

this.hypEmail.Visible = false;

this.hypUsers.Visible = false;

this.hypAdmin.Visible = false;

this.lblDiv1.Visible = true;

this.lblDiv2.Visible = true;

this.lblDiv3.Visible = true;

this.lblDiv4.Visible = false;

this.lblDiv5.Visible = false;

this.lblDiv6.Visible = false;

}
}

AddAdminreader.Close();

}
Nov 18 '05 #1
1 1258
Forget the reader, for what you are doing, you should be using the
..ExecuteScalar() method on the command object. ExecuteScalar returns the
first column of the first row of the query.

HTH,
--Michael

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:WG*********************@news-text.cableinet.net...
I've got the following code in a control and the reader doesn't seem to be
working. The connection details are correct.

Any ideas? I am reading data from this database to log the user and a lot of the details are the same.

public class AdminNavigation : System.Web.UI.UserControl

{

protected System.Web.UI.WebControls.HyperLink hypProducts;

protected System.Web.UI.WebControls.Label lblDiv1;

protected System.Web.UI.WebControls.HyperLink hypOrders;

protected System.Web.UI.WebControls.Label lblDiv2;

protected System.Web.UI.WebControls.HyperLink hypSales;

protected System.Web.UI.WebControls.Label lblDiv3;

protected System.Web.UI.WebControls.HyperLink hypReviews;

protected System.Web.UI.WebControls.Label lblDiv4;

protected System.Web.UI.WebControls.HyperLink hypEmail;

protected System.Web.UI.WebControls.Label lblDiv5;

protected System.Web.UI.WebControls.HyperLink hypUsers;

protected System.Web.UI.WebControls.Label lblDiv6;

protected System.Web.UI.WebControls.HyperLink hypAdmin;

private void Page_Load(object sender, System.EventArgs e)

{

if (!Context.User.Identity.IsAuthenticated)

{

this.hypProducts.Visible = false;

this.hypOrders.Visible = false;

this.hypSales.Visible = false;

this.hypReviews.Visible = false;

this.hypEmail.Visible = false;

this.hypUsers.Visible = false;

this.hypAdmin.Visible = false;

this.lblDiv1.Visible = false;

this.lblDiv2.Visible = false;

this.lblDiv3.Visible = false;

this.lblDiv4.Visible = false;

this.lblDiv5.Visible = false;

this.lblDiv6.Visible = false;

}

SqlConnection con;

string sql;

SqlCommand cmd;

SqlDataReader AddAdminreader;

con = new SqlConnection("data source=127.0.0.1; initial
catalog=ConsoleJunkies; user id=****; password=****");

sql = "SELECT AddAdmin FROM [Admin] WHERE AdminID='" +
Context.User.Identity.Name.ToString() + "'";

cmd = new SqlCommand(sql, con);

con.Open();

AddAdminreader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

if (AddAdminreader.Read())

{

if (AddAdminreader["AddAdmin"].ToString()=="1")

{

//Allowed full admin

this.hypProducts.Visible = true;

this.hypOrders.Visible = true;

this.hypSales.Visible = true;

this.hypReviews.Visible = true;

this.hypEmail.Visible = false;

this.hypUsers.Visible = false;

this.hypAdmin.Visible = false;

this.lblDiv1.Visible = true;

this.lblDiv2.Visible = true;

this.lblDiv3.Visible = true;

this.lblDiv4.Visible = false;

this.lblDiv5.Visible = false;

this.lblDiv6.Visible = false;

}
}

AddAdminreader.Close();

}

Nov 18 '05 #2

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

Similar topics

2
by: | last post by:
Hi, I was using the Reader class to read a binary file and I noticed that there is no PeekByte and also its not optimised when using Peek and Read in sequence. If the .Peek is called its read...
1
by: Anand | last post by:
I just implemented a program to solve reader writter prob. Wenever I run the program it seems to go into S+ state and it waits there I dont know why. When i attach gdb to one of the childs and step...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
6
by: james | last post by:
I will try to make this short and to the point. I am reading values from a file using a Binary Reader. At a particular address I can get a value of , Hex 10 or Hex 01 . (varies can be 30, 20, 02,03...
12
by: Jerry Camel | last post by:
Not sure if this is a good place to post this... I'm writing and ASP.net app using vb .net. I need to interact with a credit card reader. I have one that sits inline with the keyboard. Works...
6
by: Karl Seguin [MVP] | last post by:
The BinaryWriter/Reader's are little-endian only. Was hoping they were going to be made more flexible in 2.0, but that doesn't appear to be the case. Anyone already done all the work of...
2
by: JimmyKoolPantz | last post by:
I came across a problem today and I'm not sure what my possible solutions are. The situation is I am am using a binary reader to read data from a filestream. The data source is a dbf file. ...
6
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It...
3
by: Matt Nunnally | last post by:
I'm using XmlReader to read an XMl String such as this one: <XML_REQUEST> <USER_ID>Admin</USER_ID> <USER_PW>Test123%</USER_PW> <COMMAND>1</COMMAND> <PRESENT_FLAG>1</PRESENT_FLAG>...
0
tlhintoq
by: tlhintoq | last post by:
My project involves reading magstripe cards, capturing an ID number, then spinning off to do some other things including taking a photograph. 99% of this is done and good. All early phases of work...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.