Showing posts with label page. Show all posts
Showing posts with label page. Show all posts

Monday, March 19, 2012

Database display/manipulation

I have a web page called homepage.aspx created in Visual Studio 2005 using VB. It contains some hyperlinks on the left side. I have a database created in SQL Server 2005. I need to add, delete, edit, update data in the database directly from this same page. How can I achieve this?. i.e is it possible to, say, have a form on a section of this same web page that would allow me to directly manipulate/modify and update the database? (If you may give code, you may use abstract names for the database, tables and column and/or field names-I will understand). Many thanks in advance.

Yes, what you want to do is possible - and is one of the main points behind ASP.NET. You need to read some of the many free tutorials that are available. It's not the sort of thing anyone can describe in useful detail in a reply to a post in this forum. Here are a couple:

http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/default.aspx

|||

The links above are useful in this regard. The question I have is a bit different. I have arleady written the code to manipulate the database using GridView control. This ofcourse works in conjunction with the SqlDataSource control. The SqlDataSource control permits selecting a single database table at a time for actions of delete, add, edit etc. This means that if I need to do the above actions on many tables, I will need to reconfigure the SqlDataSource for each table. This also means that I will be able to delete, add, update data in all tables by using a number of web pages as each each table manipulation will have to be done via a seperate web page. This is ok but is very usable. I want to put,say, a form on just one web page and then this form will allow me to perform actions of add, delete, update etc on all tables using just this page. In brief: How can I fit a form on the existing web page and use this form to add, delete, udate the entire database data?.

|||The SqlDataSource will take any valid SQL or the name of a stored procedure for its CommandText property. You can assign this value at runtime in the code-behind. Most applications of the type you are describing tend to not show one "table" at a time - they show data from related tables using joins. Each data maintenance task usually has its own page/form, so adding/editing/deleting a story, for example would all be managed from one page, whereas adding/editing/deleting a contact would be done on a different one. You could do it all in one page, but I would never do so. Maintenance of code would be a mightmare.

Wednesday, March 7, 2012

Database design question....

I am building an application which is part directory (yellow page style). As I began to build the database and write up the design I found my self challenged with the following:

In part of the db I have a table for companies, categories and subcategories. The problem is that some of the companies fall into more than 1 category and I am not sure how to effeciently design this.

Can anyone share some thoughts or suggestions?::The problem is that some of the companies fall into more than 1 category and I am not
::sure how to effeciently design this.

What you need to make is a m:n relation and is a standard pattern for handling this standard problem in db design.

First, you should have three tables, but NOT two for category and subcategory.

You should have one table for Category (and a subcategory IS a category, build a tree using a relation pointing back to the table), one for the entires (companies), one for coupling one entry with one caategory - a mid table that allows you to assign an entry to x categories.

This table would basically contain one field (fk-relation) to the category, one to the entry.

Get a beginner book for SQL and relational databases that explains M:N relations in depth.|||doesn't look that hard, basic relational db design:

Category
* CatID (PK)
* CatName
* ...

Company
* CompID (PK)
* CompName
* ...

Company_Category
* CompID (PK ; FK to Company.CompID)
* CatID (PK ; FK Category.CatID)

By the way, implement subcategories as a category with a parent. Category table becomes:

Category
* CatID
* CatName
* CatParentCatID (maybe NULL for top level category)|||look up tables. Just store the primary keys in the look up tables.