![]() |
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"); Code:
@foreach(var row in query)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 |
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>Code:
var db = Database.Open("Airports"); Code:
<form runat="server" >Code:
void dosearch(Object ignored, EventArgs alsoignored) |
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... |
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. |
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.
|
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. |
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. |
| All times are GMT +1. The time now is 06:54 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.