Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2004, 08:20 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataBind Problem

I have file "names.aspx" with this code:

<%@ Page Language="vb" AutoEventWireup="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

dim myConnection as new oleDBConnection ("PROVIDER=SQLOLEDB;DATA SOURCE=212.111.111.111;UID=UserName;PWD=mypass;DAT ABASE=OurStudents" )
myConnection.open

dim cmd as oleDBCommand
dim rdr as oleDBDataReader

cmd= new oleDBCommand ("SELECT firstName FROM Students ORDER BY firstName ",myConnection)
myConnection.open()
rdr=cmd.ExecuteReader(CommandBehavior.Closeconnect ion)


with Names
     .DataSource=rdr
     .DataTextField="firstName"
     .DataValueField="firstName"
     .DataBind()

End with
rdr.close()


end sub
</script>


<html>
<head>
<title>Students</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="french">
</head>
<form method="post" runat="server" name="names" language="JavaScript">

<body bgcolor="#666666">
<div align="center">

<asp:DropDownList id="Names" runat="server" size="1" style="text-align: right; font-family:Arial; font-size:8pt; letter-spacing:-1pt; font-variant:small-caps" tabindex="5" >
</asp:DropDownList>

 </div>

</form>

</html>


Explanation: I want that the values of the dropList will be the result of the sql query. my DropList is emty!!!

What's wrong ???


 
Old November 2nd, 2004, 03:30 PM
Authorized User
 
Join Date: Oct 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default


...
cmd= new oleDBCommand ("SELECT firstName FROM Students ORDER BY firstName ",myConnection)
myConnection.open() <== DELETE THIS LINE
...
try, and post the result, please.

----------------------
wagner reatto
 
Old November 2nd, 2004, 03:51 PM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nothinh changed

 
Old November 2nd, 2004, 04:13 PM
Authorized User
 
Join Date: Oct 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default


really, it was not working.

first i changed: autoeventwireup="true"

some modifications in your code, connection string, i am using pubs, mainly:

can you adjust yours?

<%@ Page Language="vb" autoeventwireup="true" Debug="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    dim myConnection as new oleDBConnection ("Provider=SQLOLEDB.1;Password=xxx;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=xx")
    myConnection.open

    dim cmd as oleDBCommand
    dim rdr as oleDBDataReader

    cmd= new oleDBCommand ("SELECT au_lname FROM authors",myConnection)
    'myConnection.open()
    rdr=cmd.ExecuteReader(CommandBehavior.Closeconnect ion)


    with Names
          .DataSource=rdr
          .DataTextField="au_lname"
          .DataValueField="au_lname"
          .DataBind()

    End with
    rdr.close()


    end sub

</script>
<html>
<head>
<title>Students</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="french">
</head>
<form method="post" runat="server" name="names" language="JavaScript">

<body bgcolor="#666666">
<div align="center">

<asp:DropDownList id="Names" runat="server" size="1" style="text-align: right; font-family:Arial; font-size:8pt; letter-spacing:-1pt; font-variant:small-caps" tabindex="5" >
</asp:DropDownList>

 </div>

</form>

</html>



----------------------
wagner reatto





Similar Threads
Thread Thread Starter Forum Replies Last Post
Databind DarkForce ASP.NET 2.0 Basics 5 January 25th, 2011 12:04 PM
About the Databind() kuuy BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 1 November 15th, 2006 12:56 PM
Databind in TextBox kapi.goel C# 1 April 26th, 2006 05:51 AM
DataBind/DataSource problem liorlankri ADO.NET 3 November 10th, 2004 09:15 AM
Problem reading DataReader after Databind rathbird ADO.NET 1 March 10th, 2004 05:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.