Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Unable to access the data


Message #1 by lalithashank@h... on Wed, 7 Nov 2001 11:25:14
The WHERE clause does not seem to be working. Could anybody please help me 

in debigging the code down below. I am pasting the code here:



DISPLAY.ASPX



<html>

<title>ADDRESS DIARY</title>

<head>

<h1><center><u>Online Address Diary</u></center></h1>

<body bgcolor="iceblue">

<form method="POST" action="/aspnet/Projects/AddressDiary/address1.aspx" 

runat="server">

	<table>

		<tr>

		<td>Choose&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>

		<td>

		<asp:DropDownList id="droplist"  runat="server">

			<asp:ListItem>FirstName</asp:ListItem>

			<asp:ListItem>LastName</asp:ListItem>

			<asp:ListItem>City</asp:ListItem>

			<asp:ListItem>Country</asp:ListItem>

		</asp:DropDownList>

		</td>

		</tr>

	</table>

	<br><br><br><br>

	<table>

		<tr>

		<td>Enter here&nbsp;&nbsp;:</td>

		<td><asp:TextBox id="text" runat="server"/></td>

		</tr>

	</table>

	<p><center><input type="Submit" name="b1" value="Enter"></p>

</form>

</body>

</head>

</html>









ADDRESS1.ASPX



<%@ Import Namespace="System" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.ADO" %>





<html>



<script language="C#" runat="server" debug="true">



	string selfield = "";

	string seltext = "";

	

void Page_Load(Object o, EventArgs e)

{ 

	selfield = Request.Form["droplist"];

	seltext = Request.Form["text"];

	

	Response.Write(selfield);

	Response.Write(seltext);

	ADODataReader dr;

	

	String s= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = 

D:/Lalitha/databases/AddressData.mdb ";

	

	ADOConnection connec = new ADOConnection(s);

	ADOCommand comm = new ADOCommand();

	

	comm.CommandType = CommandType.Text;

	comm.CommandText = "select * from address where FirstName = 

@seltext ";

	comm.ActiveConnection = connec;

	

	connec.Open();

		

	comm.Execute(out dr);

		

	while (dr.Read())

	{

		 Response.Write(dr["FirstName"].ToString() + "  ");

		 Response.Write(dr["LastName"].ToString() + "  ");

		 Response.Write(dr["Email"].ToString() + "  ");

		 Response.Write("<br><br><br>");

	}

	

	

}

</script>

		

</html>





Thanks,

Lata.



Message #2 by "Henry Petersen" <henry@d...> on Tue, 13 Nov 2001 11:57:50
String variables in the where clause need to be surrounded by single 

quotes "'".



comm.CommandText = "select * from address where FirstName = '" & @seltext 

& "'";



> The WHERE clause does not seem to be working. Could anybody please help 

me 

> in debigging the code down below. I am pasting the code here:

> 

> DISPLAY.ASPX

> 

> <html>

> <title>ADDRESS DIARY</title>

> <head>

> <h1><center><u>Online Address Diary</u></center></h1>

> <body bgcolor="iceblue">

> <form method="POST" action="/aspnet/Projects/AddressDiary/address1.aspx" 

> runat="server">

> 	<table>

> 		<tr>

> 		<td>Choose&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>

> 		<td>

> 		<asp:DropDownList id="droplist"  runat="server">

> 			<asp:ListItem>FirstName</asp:ListItem>

> 			<asp:ListItem>LastName</asp:ListItem>

> 			<asp:ListItem>City</asp:ListItem>

> 			<asp:ListItem>Country</asp:ListItem>

> 		</asp:DropDownList>

> 		</td>

> 		</tr>

> 	</table>

> 	<br><br><br><br>

> 	<table>

> 		<tr>

> 		<td>Enter here&nbsp;&nbsp;:</td>

> 		<td><asp:TextBox id="text" runat="server"/></td>

> 		</tr>

> 	</table>

> 	<p><center><input type="Submit" name="b1" value="Enter"></p>

> </form>

> </body>

> </head>

> </html>

> 

> 

> 

> 

> ADDRESS1.ASPX

> 

> <%@ Import Namespace="System" %>

> <%@ Import Namespace="System.Data" %>

> <%@ Import Namespace="System.Data.ADO" %>

> 

> 

> <html>

> 

> <script language="C#" runat="server" debug="true">

> 

> 	string selfield = "";

> 	string seltext = "";

> 	

> void Page_Load(Object o, EventArgs e)

> { 

> 	selfield = Request.Form["droplist"];

> 	seltext = Request.Form["text"];

> 	

> 	Response.Write(selfield);

> 	Response.Write(seltext);

> 	ADODataReader dr;

> 	

> 	String s= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = 

> D:/Lalitha/databases/AddressData.mdb ";

> 	

> 	ADOConnection connec = new ADOConnection(s);

> 	ADOCommand comm = new ADOCommand();

> 	

> 	comm.CommandType = CommandType.Text;

> 	comm.CommandText = "select * from address where FirstName = 

> @seltext ";

> 	comm.ActiveConnection = connec;

> 	

> 	connec.Open();

> 		

> 	comm.Execute(out dr);

> 		

> 	while (dr.Read())

> 	{

> 		 Response.Write(dr["FirstName"].ToString() + "  ");

> 		 Response.Write(dr["LastName"].ToString() + "  ");

> 		 Response.Write(dr["Email"].ToString() + "  ");

> 		 Response.Write("<br><br><br>");

> 	}

> 	

> 	

> }

> </script>

> 		

> </html>

> 

> 

> Thanks,

> Lata.

> 

Message #3 by Tom Whittington <whitrt@s...> on Tue, 13 Nov 2001 07:56:13 -0600
Make sure you are typing the value in the FirstName field in the same case as it is in your database.



whitrt@s...



On Tuesday, November 13, 2001 5:58 AM, Henry Petersen [SMTP:henry@d...] wrote:

> String variables in the where clause need to be surrounded by single 

> quotes "'".

> 

> comm.CommandText = "select * from address where FirstName = '" & @seltext 

> & "'";

> 

> > The WHERE clause does not seem to be working. Could anybody please help 

> me 

> > in debigging the code down below. I am pasting the code here:

> > 

> > DISPLAY.ASPX

> > 

> > <html>

> > <title>ADDRESS DIARY</title>

> > <head>

> > <h1><center><u>Online Address Diary</u></center></h1>

> > <body bgcolor="iceblue">

> > <form method="POST" action="/aspnet/Projects/AddressDiary/address1.aspx" 

> > runat="server">

> > 	<table>

> > 		<tr>

> > 		<td>Choose&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>

> > 		<td>

> > 		<asp:DropDownList id="droplist"  runat="server">

> > 			<asp:ListItem>FirstName</asp:ListItem>

> > 			<asp:ListItem>LastName</asp:ListItem>

> > 			<asp:ListItem>City</asp:ListItem>

> > 			<asp:ListItem>Country</asp:ListItem>

> > 		</asp:DropDownList>

> > 		</td>

> > 		</tr>

> > 	</table>

> > 	<br><br><br><br>

> > 	<table>

> > 		<tr>

> > 		<td>Enter here&nbsp;&nbsp;:</td>

> > 		<td><asp:TextBox id="text" runat="server"/></td>

> > 		</tr>

> > 	</table>

> > 	<p><center><input type="Submit" name="b1" value="Enter"></p>

> > </form>

> > </body>

> > </head>

> > </html>

> > 

> > 

> > 

> > 

> > ADDRESS1.ASPX

> > 

> > <%@ Import Namespace="System" %>

> > <%@ Import Namespace="System.Data" %>

> > <%@ Import Namespace="System.Data.ADO" %>

> > 

> > 

> > <html>

> > 

> > <script language="C#" runat="server" debug="true">

> > 

> > 	string selfield = "";

> > 	string seltext = "";

> > 	

> > void Page_Load(Object o, EventArgs e)

> > { 

> > 	selfield = Request.Form["droplist"];

> > 	seltext = Request.Form["text"];

> > 	

> > 	Response.Write(selfield);

> > 	Response.Write(seltext);

> > 	ADODataReader dr;

> > 	

> > 	String s= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = 

> > D:/Lalitha/databases/AddressData.mdb ";

> > 	

> > 	ADOConnection connec = new ADOConnection(s);

> > 	ADOCommand comm = new ADOCommand();

> > 	

> > 	comm.CommandType = CommandType.Text;

> > 	comm.CommandText = "select * from address where FirstName = 

> > @seltext ";

> > 	comm.ActiveConnection = connec;

> > 	

> > 	connec.Open();

> > 		

> > 	comm.Execute(out dr);

> > 		

> > 	while (dr.Read())

> > 	{

> > 		 Response.Write(dr["FirstName"].ToString() + "  ");

> > 		 Response.Write(dr["LastName"].ToString() + "  ");

> > 		 Response.Write(dr["Email"].ToString() + "  ");

> > 		 Response.Write("<br><br><br>");

> > 	}

> > 	

> > 	

> > }

> > </script>

> > 		

> > </html>

> > 

> > 

> > Thanks,

> > Lata.

> > 

> 




> 


  Return to Index