Subject: DataBind Problem
Posted By: liorlankri Post Date: 11/2/2004 7:20:21 AM
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;DATABASE=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.Closeconnection)


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 ???


Reply By: wagner reatto Reply Date: 11/2/2004 2:30:45 PM

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

----------------------
wagner reatto
Reply By: liorlankri Reply Date: 11/2/2004 2:51:20 PM
nothinh changed

Reply By: wagner reatto Reply Date: 11/2/2004 3:13:49 PM

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.Closeconnection)


    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

Go to topic 21561

Return to index page 726
Return to index page 725
Return to index page 724
Return to index page 723
Return to index page 722
Return to index page 721
Return to index page 720
Return to index page 719
Return to index page 718
Return to index page 717