Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-02-2013, 01:16 AM   PM User | #1
bdenny20
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
bdenny20 is an unknown quantity at this point
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
bdenny20 is offline   Reply With Quote
Old 02-03-2013, 04:00 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-04-2013, 03:27 PM   PM User | #3
bdenny20
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
bdenny20 is an unknown quantity at this point
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...
bdenny20 is offline   Reply With Quote
Old 02-04-2013, 10:37 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-05-2013, 11:17 AM   PM User | #5
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Old 02-05-2013, 04:32 PM   PM User | #6
bdenny20
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
bdenny20 is an unknown quantity at this point
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.
bdenny20 is offline   Reply With Quote
Old 02-05-2013, 04:32 PM   PM User | #7
bdenny20
New Coder

 
Join Date: Jan 2013
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
bdenny20 is an unknown quantity at this point
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.
bdenny20 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:05 PM.


Advertisement
Log in to turn off these ads.