Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Returning Search Results

    Hi again,
    Require some more help.
    So, I'm using WebMatrix as a learning platform with ASP.NET. Having a good time.

    I ran through the "Bakery" demo from W3Schools, and I am trying to make a database search function based on what I learned from the demo. I haven't had much luck.

    Well, I made a demo database (Airports.sdf) with a table by the same name. It has 5 sample rows with 5 columns. There is an ID column, but the primary column users would use to search by is the column called 'ICAO', a four letter code.


    So, from the demo, I learned about
    Code:
    var db = Database.Open("Airports"); 
    var query = db.Query("SELECT * FROM Airports ORDER BY ID");
    with

    Code:
    @foreach(var row in query)
    in an HTML table. Makes all the entries show up nicely. Cool.


    What I am trying to do is take a text input bar, and a submit button, and have a user be able to enter the 4 letter ICAO, and after clicking the submit button, the corresponding entry and all it's columns appear in a HTML table.

    So far I haven't gotten the right phrasing of the db.Query and I don't know how to tie it to a button.

    Google suggestions gave me incredibly complicated solutions that I can not understand at this point, at first I thought this was a simple process, but could I be wrong?


    Thanks in advance.

    Billr

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    It depends on if you want to use "pure" ASP.NET or you don't mind a bit of hacking.

    If you are using pure ASP.NET, you would want to create a FormView, most likely.

    If you don't mind hacking:
    Code:
    <html>
    <body>
    <form action="findAirport.aspx" method="post">
    ICAO code: <input name="icao" />
    <input type="submit" />
    </form>
    </body>
    </html>
    and then your "findAirport.aspx" page is dirt simple:
    Code:
    var db = Database.Open("Airports"); 
    var query = db.Query("SELECT * FROM Airports " + Request.Form("icao") + " ORDER BY ID");
    ... etc. ...
    But if you were to use ASP.NET form controls, you'd use something like
    Code:
    <form runat="server" >
    <asp:TextBox runat="server" id="icao" />
    <asp:Button OnClick="dosearch" Text="Search by ICAO" runat="server" />
    </form>
    and then your backend code would do:
    Code:
    void dosearch(Object ignored, EventArgs alsoignored)
    {
        var db = Database.Open("Airports"); 
        var query = db.Query("SELECT * FROM Airports " + icao.Value + " ORDER BY ID");
        ...
    These are glittering generalities. Read through a few more tutorials and you'll get the hang of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, haven't checked in for a minute. Thanks for getting back to me. I get what you're saying, which is awesome, because normally that doesn't happen. Still pretty green.

    Now, on a similar note, after I posted that, I started looking at alternatives to my goal, to kinda broaden the hypothetical horizons. I've created a MySQL database and am manipulating it with PHP. I actually did get a working form on that, real simple though, only accepts uppercase letters, exact matches (KSAN and SAN are the same thing) and nothing special happens if a non-valid entry is entered.

    BUT

    That's neither here nor there, I'll post something in the PHP forum later,

    My question is, is there a particular advantage to using PHP and MySQL compared to ASP.NET and SQL? The only thing that really stands out is ASP.NET seems to a be a little more user friendly and easier to understand (var vs. $) Also, having phpMyAdmin is a nice tool.

    Just wondering...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Ummm...actually, var is a terrible hack, if you are using C# for your coding language. Using var means that the compiler has to do runtime type checking, so you get a lot less efficiency than if you use the proper type names. C# added var to make it easier to code, but I hate it. It means you sacrifice performance because the programmer doesn't want to learn the language.

    The real advantage to using ASP.NET is that, if you use a tool such as Web Developer Express, you can use drag-and-drop to create your web pages (the basics, that is) and then you just have to write the "backend" code to handle events on the pages.

    But if you aren't using such a tool, and if performance isn't an issue, then there's not much difference between ASP.NET and PHP coding.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    fwiw- As Old Pedant stated, his code is a hack.... it can be refined a h*** of a lot more, but (and I assume he posted it so it would be on your playing field of understanding) there are many ways of doing this- and it all depends on your style of coding (or if you are working for someone their requirements/style of coding). For example if I were doing this I would (in the code behind) on page load (!postback) hit the db and populate a collection (maybe a datatable, if needed a custom class) and then create the appropriate html objects and litterally add them to the page at runtime. This allows you to seperate your data access layer and buisiness layers from your presentation layer. But that is a waaaaaay to much to dump on someone learning.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #6
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep, as I was reading that I swear I started to smoke a little out of my ears. It's okay, I'm not doing anything for anyone. Just a little experimentation on my own behalf, so I can go at my own rate and not worry.

    If there is anything I've learned for sure so far, it that's there are many ways to go about doing the same thing, and everyone's got there own method. Kind of counter productive though when someone gives me a pointer on something, and when I re-post latter on the subject, someone else is all.. "no, no, no, do it like this..." Oh well, nature of the game I suppose.

  • #7
    New Coder
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep, as I was reading that I swear I started to smoke a little out of my ears. It's okay, I'm not doing anything for anyone. Just a little experimentation on my own behalf, so I can go at my own rate and not worry.

    If there is anything I've learned for sure so far, it that's there are many ways to go about doing the same thing, and everyone's got there own method. Kind of counter productive though when someone gives me a pointer on something, and when I re-post latter on the subject, someone else is all.. "no, no, no, do it like this..." Oh well, nature of the game I suppose.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •