call single field vs. all of them

Discussion in 'ASP.NET 2.0' started by joshbeagley, Aug 26, 2006.

  1. joshbeagley

    joshbeagley Guest

    I just successfully used one ofw3school's codes to connect to northwind.mdb In this code, all fields are called by sql and each individual field is displayedwaaay down in the html. How would I reference one field in the script? My goal is to call the script onsubmit, so if formpassword = databasepassword then login = true, else false. I'm able to query the correct record with no problem, I just need to use the passwordvalue in the database for comparing with the form input. I'm sure this is an easy fix, but I can't find the right tutorial anywhere. Thanks for the help!

    w3school's code:
    <%@ Import Namespace="System.Data.OleDb" %><script runat="server">
    sub Page_Load
    dim dbconn,sql,dbcomm,dbread
    dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
    data source=" &amp; server.mappath("northwind.mdb"))
    dbconn.Open()
    sql="SELECT * FROM customers"
    dbcomm=New OleDbCommand(sql,dbconn)
    dbread=dbcomm.ExecuteReader()
    customers.DataSource=dbread
    customers.DataBind()
    dbread.Close()
    dbconn.Close()
    end sub
    </script><html>
    <form runat="server">
    <asp:Repeater id="customers" runat="server"><HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>Companyname</th>
    <th>Contactname</th>
    <th>Address</th>
    <th>City</th>
    </tr>
    </HeaderTemplate><ItemTemplate>
    <tr>
    <td><%#Container.DataItem("companyname")%></td>
    <td><%#Container.DataItem("contactname")%></td>
    <td><%#Container.DataItem("address")%></td>
    <td><%#Container.DataItem("city")%></td>
    </tr>
    </ItemTemplate><FooterTemplate>
    </table>
    </FooterTemplate></asp:Repeater>
    </form></body>
    </html>Thanks again!Josh
     
  2. You can reference the one field you need in the datareader object. I think our knowledgebase article has a better example of this. See http://kb.discountasp.net/article.aspx?id=10023. The field/column can be referenced with an index or string name.

    It also sounds like you're trying to create some login interface. You might want to look into the Membership provider in ASP.NET 2.0 where the username/password checking is done automatically.

    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. joshbeagley

    joshbeagley Guest

    Aristotle, thanks for the reference, I'll give it a shot. And I'll look for the membership providers.I've only been able to come up withthe login and change password controls, ect. By the time I learn those, I couldmake them myself. In classic asp I used session vars to hold the users member name and permission levels, but I've heard session vars aren't very secure. Is that true?


    Thanks,


    Josh
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    i am not aware of any major security issue with using Session variable. Most website (eCommerce, banks, etc.) rely on session.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. You probably misheard someone say they are not very Scalable, which is true. You want to use Session variables sparingly.


    Though it is untrue that they are insecure.



    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  6. joshbeagley

    joshbeagley Guest

    Glad to hear that. I use session variables only when someone signs in, setting thier username, permissions and whatnot. They're definately easy to work with. Speaking of security,does anyone know of a good tutorialon encrypting querystrings? Everything I've found so far is pretty complex and I just haven't had the energy to get into it. Thanks


    Josh
     

Share This Page