473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding columns to a database table programmatically...

Hi,

I've been tasked to write a windows app that allows people to enter
transactions. For each transaction, there can be an unknown number of items,
and as a person enters an item, the program asks if there are more items. If
yes, a new set of input boxes are created dynamically. What I was wondering
is this - not knowing how many items are going to be entered, is there a way
that I can change the layout of a database table depending on the number of
items entered? After the initial creation of the database, with a set number
of item columns, is there a way for me, (ie. the program), to alter/change
the database layout?

Any help is deeply appreciated...

CDB
Sep 7 '07 #1
5 3413
On Sep 7, 3:22 pm, cdbiggs <cdbi...@discussions.microsoft.comwrote:
Hi,

I've been tasked to write a windows app that allows people to enter
transactions. For each transaction, there can be an unknown number of items,
and as a person enters an item, the program asks if there are more items. If
yes, a new set of input boxes are created dynamically. What I was wondering
is this - not knowing how many items are going to be entered, is there a way
that I can change the layout of a database table depending on the number of
items entered? After the initial creation of the database, with a set number
of item columns, is there a way for me, (ie. the program), to alter/change
the database layout?

Any help is deeply appreciated...

CDB
Nicholas made a good comment, but if you still want to programmically
alter a table's definition, it depends on the dabase providor. If
Microsoft SQL Server, all you need to do is issue an ALTER TABLE SQL
command.

Sep 7 '07 #2
za***@construction-imaging.com wrote:
On Sep 7, 3:22 pm, cdbiggs <cdbi...@discussions.microsoft.comwrote:
>Hi,

I've been tasked to write a windows app that allows people to enter
transactions. For each transaction, there can be an unknown number of items,
and as a person enters an item, the program asks if there are more items. If
yes, a new set of input boxes are created dynamically. What I was wondering
is this - not knowing how many items are going to be entered, is there a way
that I can change the layout of a database table depending on the number of
items entered? After the initial creation of the database, with a set number
of item columns, is there a way for me, (ie. the program), to alter/change
the database layout?

Any help is deeply appreciated...

CDB

Nicholas made a good comment, but if you still want to programmically
alter a table's definition, it depends on the dabase providor. If
Microsoft SQL Server, all you need to do is issue an ALTER TABLE SQL
command.
That *would* be the way to do it, but frankly it would be a disastrous
way to do things from a DBA side of things.. Really..

Basic table with ID column, client/transaction column and item column.
The ID is invisible, and you can get any/all items per transaction nice
and simply.. It also allows for basic querying based on transaction *or*
item, if you're thinking long term.

but yah.. having a table that grows/shrinks columns based on arbitrary
item count is going to make your DBA cry.

P.
Sep 7 '07 #3
CDB,

Here are some other options to consider so (like Nicholas said) you can keep
the DBA happy (maybe :)).

1. You could possibly store all items in a large varchar column as a
delimitted string (i.e. comma, etc.).
Of course this assumes that all potentially entered items would fit.

2. Some databases allow for the creation of multi-valued columns in a table.
I don't believe Sql Server
supports this yet. Multi-valued columns allow for 0-n items in a single
column where n is unknown at
design time. These have actually been around for quite a while in
databases like universe and pick.
Some relational vendors have recently added support for them to their
products (i.e. Informix, DB2).

3. Some databases allow for the creation of XML valued columns. Sql Server
2005 supports this column
type. If you wanted to go this route you can stuff whatever XML you
want in the column.

There are other ways of going about it (like Nicholas fine suggestion of
using one row per item in a
separate related table).

And of course you can always just alter the table by adding more columns.

HTH
--
Gregg Walker

Sep 7 '07 #4
For some reason, I didn't get Nicholas' reply, but, what you wrote really
helps. I don't know why I didn't think of setting up another table to accept
each item in its own row. Also, I like the idea of possibly making the items
comma seperated.

Thank you all for the help. If you could post what Nicholas wrote so I
could see that would be most helpful.

Thanks

CDB

"Gregg Walker" wrote:
CDB,

Here are some other options to consider so (like Nicholas said) you can keep
the DBA happy (maybe :)).

1. You could possibly store all items in a large varchar column as a
delimitted string (i.e. comma, etc.).
Of course this assumes that all potentially entered items would fit.

2. Some databases allow for the creation of multi-valued columns in a table.
I don't believe Sql Server
supports this yet. Multi-valued columns allow for 0-n items in a single
column where n is unknown at
design time. These have actually been around for quite a while in
databases like universe and pick.
Some relational vendors have recently added support for them to their
products (i.e. Informix, DB2).

3. Some databases allow for the creation of XML valued columns. Sql Server
2005 supports this column
type. If you wanted to go this route you can stuff whatever XML you
want in the column.

There are other ways of going about it (like Nicholas fine suggestion of
using one row per item in a
separate related table).

And of course you can always just alter the table by adding more columns.

HTH
--
Gregg Walker

Sep 8 '07 #5
CDB,

Here is the link to my original response:

http://groups.google.com/group/micro...47dd7c7b28fe39
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"cdbiggs" <cd*****@discussions.microsoft.comwrote in message
news:4B**********************************@microsof t.com...
For some reason, I didn't get Nicholas' reply, but, what you wrote really
helps. I don't know why I didn't think of setting up another table to
accept
each item in its own row. Also, I like the idea of possibly making the
items
comma seperated.

Thank you all for the help. If you could post what Nicholas wrote so I
could see that would be most helpful.

Thanks

CDB

"Gregg Walker" wrote:
>CDB,

Here are some other options to consider so (like Nicholas said) you can
keep
the DBA happy (maybe :)).

1. You could possibly store all items in a large varchar column as a
delimitted string (i.e. comma, etc.).
Of course this assumes that all potentially entered items would fit.

2. Some databases allow for the creation of multi-valued columns in a
table.
I don't believe Sql Server
supports this yet. Multi-valued columns allow for 0-n items in a
single
column where n is unknown at
design time. These have actually been around for quite a while in
databases like universe and pick.
Some relational vendors have recently added support for them to their
products (i.e. Informix, DB2).

3. Some databases allow for the creation of XML valued columns. Sql
Server
2005 supports this column
type. If you wanted to go this route you can stuff whatever XML you
want in the column.

There are other ways of going about it (like Nicholas fine suggestion of
using one row per item in a
separate related table).

And of course you can always just alter the table by adding more columns.

HTH
--
Gregg Walker

Sep 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bubbles | last post by:
i have a HTML file and it already has a HTML table and a few rows created by default.. however, i would like to add more rows to this table programmatically may i know how?
2
by: Gail Zacharias | last post by:
I am investigating the possibility of using pgsql as the database in an application. I have some unusual requirements that I'd like to ask you all about. I apologize in advance if my terminology is...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
2
by: Viorel | last post by:
Adding new row with default values. In order to insert programmatically a new row into a database table, without direct "INSERT INTO" SQL statement, I use the well-known DataTable.NewRow,...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
12
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.