Fires of Heaven Guild Message Board  

Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
Or, use your gamerDNA username: (more...)
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-28-2007, 01:54 PM   #1 (permalink)
tikkus
Banned
 
Join Date: Nov 2003
Posts: 1,219
-3 Internets
[VB.NET] Coding Structure and Syntax Help

I'm doing a project over Christmas break (for real, this time :P) using SQL Server 2k5 and VB.NET/ASP.NET. Currently, I have the database designed for core functionality and all stored procedures I'll need to manipulate it at this stage of the development.

My big question is how to implement it using VB.NET. My understanding so far is that the code structure looks like this:

moduleOne.vb // In the Apps_Code directory
moduleOne.aspx.vb // The code-behind in the root directory
moduleOne.aspx // The front-end file in the root directory

My big question is: What would need to go in each one of those? Its a bit overwhelming right now to jump in and just start coding and I've Googled for about 2 hours to no avail of what I'm looking for.

FYI: This is just simple database functionality integrated into a website (at this point, anyway) - adding, deleting an entry from a database and displaying the results on the screen.

Anyway, if someone can give me a run-down of the orthodox coding practices in regards to the three programming files, and maybe provide a good reference for VB.NET/ASP.NET I would be eternally grateful.
tikkus is offline   Reply With Quote
Old 12-28-2007, 05:01 PM   #2 (permalink)
Phelps McManus
I'm dangerous!
 
Join Date: Jan 2002
Location: Atlanta
Posts: 891
The aspx file is your typical ASP web page, filled with HTML and ASP tags. It is what web browsers specifically open.

The aspx.vb file is strictyly VB code tied to the similarly named aspx file. It is where all of the event handling and Page class function overrides go. While it is possible to put all of that in the aspx file, putting it here is cleaner and allows you to hide most your code from the client.

Any old vb file can be referenced from the aspx.vb file, as if it were any normal, mult-sourcefile project.

Are you not using VS2005 to create this project? It generates most of the boilerplate code for you. I also recommend using it for Intellisense.

As far as databases go, I hope you are familiar with ADO.NET (or not using it) or you have a long road ahead of you. ASP.NET is cake in comparison.

edit: Oh and you seem to be missing a Web.config file, which kind of ties the whole project together and allows you to manipulate some global parameters.

Last edited by Phelps McManus : 12-28-2007 at 05:05 PM.
Phelps McManus is offline   Reply With Quote
Old 12-28-2007, 06:16 PM   #3 (permalink)
tikkus
Banned
 
Join Date: Nov 2003
Posts: 1,219
-3 Internets
Quote:
Originally Posted by Phelps McManus View Post
The aspx file is your typical ASP web page, filled with HTML and ASP tags. It is what web browsers specifically open.

The aspx.vb file is strictyly VB code tied to the similarly named aspx file. It is where all of the event handling and Page class function overrides go. While it is possible to put all of that in the aspx file, putting it here is cleaner and allows you to hide most your code from the client.

Any old vb file can be referenced from the aspx.vb file, as if it were any normal, mult-sourcefile project.

Are you not using VS2005 to create this project? It generates most of the boilerplate code for you. I also recommend using it for Intellisense.

As far as databases go, I hope you are familiar with ADO.NET (or not using it) or you have a long road ahead of you. ASP.NET is cake in comparison.

edit: Oh and you seem to be missing a Web.config file, which kind of ties the whole project together and allows you to manipulate some global parameters.
That clarified quite a bit. I have no ADO.NET experience, but I bought a book on it recently.

The main reason why I'm doing this is I just got hired on a small software company and they're using this technology on a contract they have. I have no experience with VB.NET and was trying to get a feel with how everything worked.

So, for clarification:

The .vb file in the App_Code directory will have my calls to the storage procedures and all major functions that will be used to manipulate the database.

The .aspx.vb will be handling all of the page code, such as for an "add" button I'd have OnClick being the event and the function in the .vb file that corresponds to that.

The .aspx will contain the events I've defined in the .aspx.vb file.

I do have Visual Studio 2005, but I'm just trying to get a feel for everything. I'm a little overwhelmed at the moment and have about a week to become productive at this crap.

Thanks for the help, it definitely clarified a lot. Do you have any good resources to look at for the kind of thing I'm trying to accomplish?
tikkus is offline   Reply With Quote
Old 12-28-2007, 09:14 PM   #4 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
You can skip using a bunch of ADO.NET and do a ton of database stuff just in the markup with some declarative databinding. Form views, grid views and repeaters are some controls to look into that may do what you need.
Hachima is offline   Reply With Quote
Old 12-28-2007, 10:10 PM   #5 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
Here is a little sample of what I'm talking about. You should have the northwind DB installed to use this. This page uses all markup to do DB access/updates without any codebehind.
Attached Files
File Type: zip NWDemo.zip (3.1 KB, 26 views)
Hachima is offline   Reply With Quote
Old 12-28-2007, 10:54 PM   #6 (permalink)
tikkus
Banned
 
Join Date: Nov 2003
Posts: 1,219
-3 Internets
So I can put the connection method in the web.config file and just call the connection via the .aspx page?

One question: How are queries handled? When I get the data, is it returned as an array or an object?
tikkus is offline   Reply With Quote
Old 12-28-2007, 11:53 PM   #7 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
Yeah, you want to keep your connection string in there and reference it. That way if you need to make a change you just have one place to change it.

Usually you don't need to worry about the data that comes from the sqldatasource. Anything that is databound to it will be populated. You can can make the sqldatasource has update select delete insert methods you can call. There are all sorts of paramaters available to use with the datasorce too. Like pulling data from session,query string, form data.
Hachima is offline   Reply With Quote
Old 12-29-2007, 03:26 AM   #8 (permalink)
tikkus
Banned
 
Join Date: Nov 2003
Posts: 1,219
-3 Internets
Well, I'm accessing the database through localized stored procedures in the SQL server. That way, all I'll have to change is one query and it will be affected through the entire program.

I'm not entirely sure how data is handled when accessing it in that manner.
tikkus is offline   Reply With Quote
Old 12-29-2007, 07:36 AM   #9 (permalink)
Phelps McManus
I'm dangerous!
 
Join Date: Jan 2002
Location: Atlanta
Posts: 891
I believe the data is returned as a table or a collection of rows, that you can requery as you please or just "Select *" to look at all of them. I would start looking through MSDN. It will tell you exactly what will be returned and how to manipulate it. They also have sample code in VB, C#, and Java.
Phelps McManus is offline   Reply With Quote
Old 12-29-2007, 10:46 AM   #10 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
http://www.fohguild.org/forums/newreply.php?do=newreply&noquote=1&p=940499

When using an SqlDataSource in markup you dont need to worry about the type. You just have to worry about databinding the information to the correct controls.

If you are programatically using an sqldatasource the Select command returns an IEnumerable which you can cast to a DataView. For a lot of stuff there should be no reason to start digging in to this but sometimes you need to.

For example here is a way to pull some data programatically. Its C# so you will have to translate it to VB. This isn't part of an actual page but I'll just make up a snippet.

Code:
DataView dv = (DataView)SqlDataSourceProductList.Select(new DataSourceSelectArguments()); //pulls all the info from the DB dv.Table.PrimaryKey = new DataColumn[] { dv.Table.Columns["ProductID"] };//ProductID is the primary key in the DB DataRow dr = dv.Table.Rows.Find(lbxProducts.SelectedValue);//the Value property of the listbox named lbxProducts are ProductID values. This will pull the row with that ProductID int quantityLeft = (int)dr["Quantity"];//retrieve the quantity value from the row with the ProductID we had selected
Hachima is offline   Reply With Quote
Old 01-01-2008, 05:07 AM   #11 (permalink)
tikkus
Banned
 
Join Date: Nov 2003
Posts: 1,219
-3 Internets
Could someone also explain Events to me as well?

For example, what exactly does it mean with....

ByVal Src As Object, ByVal Args As EventArgs
tikkus is offline   Reply With Quote
Old 01-01-2008, 06:00 PM   #12 (permalink)
Hachima
Registered User
 
Join Date: Oct 2004
Posts: 1,758
I take it you are looking at the signature of an event handler? The first parameter specifies the object that fired the event. The second parameter is a generic EventArgs object that can contain specific information about the event that was fired.

Some controls use specific EventArgs. Like a Calendar control has a DayRender event with DayRenderEventArgs. DayRenderEventArgs has a Cell property that lets you modify the css/layout/print text for that particular cell. It also has a Day property that gives you information about the day that is being rendered on the calendar.

In WinForms apps, buttons have a MouseClick event which use MouseEventArgs which has properties such as the X and Y cords of the mouse click, the mouse button that was clicked. The object that triggered the event would be the Button that was clicked.
Hachima is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
uberguilds network



All times are GMT -7. The time now is 01:17 AM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6