473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

store info in database.

Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other
id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???

Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)

Christopher Brandsdal

Jul 19 '05 #1
4 2672
If you have two tables in your database, one called Companies and one called
People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being
the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple
companies then you need to create a many-to-many relationship-- meaning one
company has many people working for it, but also one person has worked (or
is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a
duplicate entry would be acceptable. For example: if you are tracking an
employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys as
Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a
problematic solution. Besides being difficult to maintain and parse....how
would you decide how much data the field could hold?


"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???
Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)
Christopher Brandsdal

Jul 19 '05 #2
Ok. Thanks I understand.

But the the problem is that both companies and persons are in the same
table...

Should I change it to 2 different tables???

and how will the code look like with the join command???

When I add a person to the database I have to be able to select multiple
companies for that person...
(the companies are added in advance)

"TomB" <sh*****@hotmai l.com> skrev i melding
news:O1******** ******@TK2MSFTN GP12.phx.gbl...
If you have two tables in your database, one called Companies and one called People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being
the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple
companies then you need to create a many-to-many relationship-- meaning one company has many people working for it, but also one person has worked (or
is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a
duplicate entry would be acceptable. For example: if you are tracking an
employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys as Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a problematic solution. Besides being difficult to maintain and parse....how would you decide how much data the field could hold?


"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies in the same database. I wonder how i could connect a person to several

other
id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the ,

???

Hmm..
This may be difficult to ynderstand, but I have tried my best to explain

;)

Christopher Brandsdal


Jul 19 '05 #3
Unless there's a REALLY good reason, then you should separate the data into
two tables. Try to think of the contents of a table as being a list of
similar entities. So Companies would be in a separate table from People,
because they are dissimilar.

If you are using Access create the tables you need, then go the
relationships (icon on toolbar) to indicate how the tables are related.
Once Access "knows" how the tables are related, you can go into the Query
Wizard and create a query (or use design view)
View the query to ensure the results are what you expect.
Switch to SQL view of the query, and you'll see the SQL statement needed to
select the data.

When you are adding people to database, you want to add multiple companies.
I assume therefore, that you'll have three tables (many to many)

Present the form with fields for the Person information, and checkboxes for
the available companies. To make life easier, give each checkbox the same
name, but a different value. For example:

<input type=checkbox name=Companies value="3">McDon alds
<input type=checkbox name=Companies value="4">Burge r King

Where 3 and 4 are the UniqueIDs of the two companies.

On the page the form is posted to, "Requesting " the Companies will return a
comma separated list of the selected companies. So if both of the values
were selected in the example above, then Request.Form("C ompanies") would
return "3, 4"

You will then have to insert the data in three steps.
1) insert the person's information
2)get the new person's ID
3) insert the companies
<%
'Step One
Dim sSQL
Dim RS
Dim PersonID
Dim arrCompanies
Dim iLoop

sSQL="INSERT INTO People (FirstName, LastName) VALUES('Joe',
'Blow')" 'Obviously you would use the values passed in

CN.Execute sSQL 'I'm assuming CN is a properly opened connection
object
'Step Two
Set RS=CN.Execute(" SELECT @@IDENTITY") 'returns the most recently
created Identity on this connection
PersonID=RS.Fie lds(0).Value
Set RS=nothing

'Step Three
arrCompanies=Sp lit(Request.For m("Companies"), ",") 'split takes a
string and "splits" it into an array based on the delimiter (in this case a
comma)

For iLoop = 0 to UBound(arrCompa nies)
sSQL="INSERT INTO CompaniesPeople Join (PersonID, CompanyID)
VALUES(" & PersonID & ", " & Trim(arrCompani es(iLoop)) & ")"
CN.Execute sSQL
Next

%>

Bear in mind, that if any of the inserts fail the previous ones would have
succeeded so you would have only some of the values in.
A better solution would use a transaction, and the best solution would use a
Stored Procedure (Sql Server)

"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:ev******** ******@TK2MSFTN GP12.phx.gbl...
Ok. Thanks I understand.

But the the problem is that both companies and persons are in the same
table...

Should I change it to 2 different tables???

and how will the code look like with the join command???

When I add a person to the database I have to be able to select multiple
companies for that person...
(the companies are added in advance)

"TomB" <sh*****@hotmai l.com> skrev i melding
news:O1******** ******@TK2MSFTN GP12.phx.gbl...
If you have two tables in your database, one called Companies and one called
People, you have to make a decision....

If you just want to track a person's current company, and you are assuming
that the people only work for one company at a time, then you add a
CompanyID foreign key field to the People table. This is a one-to-many
relationship with the company being on the "one" side and the People being the "many", thus one company has many people working for it.

If you want to track a person's employment history, or allow for multiple companies then you need to create a many-to-many relationship-- meaning

one
company has many people working for it, but also one person has worked (or is working) for many companies.

To create the many-to-many relationship you create a "join" table, which
contains foreign keys to both the Company table and the People table.

Usually, the join table's primary key is the combination of the Foreign
Keys. This prevents duplicate entries. There are times, however; when a duplicate entry would be acceptable. For example: if you are tracking an employment history, it could be possible for a person to work at one
company, leave it, then come back to it. If you'd used the Foreign keys

as
Primary key, then you wouldn't be able to add the return to the same
company.

Your idea to store the information in a single field (comma separated) is a
problematic solution. Besides being difficult to maintain and

parse....how
would you decide how much data the field could hold?


"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with

companies in the same database. I wonder how i could connect a person to several

other
id's in a table.

I wonder if I can make a string in the database that holds all the id's separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the

, ???

Hmm..
This may be difficult to ynderstand, but I have tried my best to
explain ;)

Christopher Brandsdal



Jul 19 '05 #4
Hello,

Use the split command, which will then parse out all the commas and put all
the numbers into an array.
Dim tempStr
tempStr = "1,2,3,4,5,6,7, 8"

Dim tempArray
tempArray = split(tempStr, ",")

Dim maxArrayElement s
maxArrayElement s = UBound(tempArra y)

Dim arrayIndex
arrayIndex = 0

For arrayIndex = 0 to maxArrayElement s - 1
' do what you need to do here, using
' tempArray(array Index)
' to get at the current array value
Next

This example is in vbscript, although Javascript also supports the SPLIT
command....

Joe

"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:eB******** ******@TK2MSFTN GP12.phx.gbl...
Hi!

I have a delicatg problem....
I have made a registration form for adding my friends information in a
database. The problem is that I want to connect the persons with companies
in the same database. I wonder how i could connect a person to several other id's in a table.

I wonder if I can make a string in the database that holds all the id's
separated with , for example....?

the string would then look like this:
1,4,6,22,56
for example...

But how can I then open this string and separate the numbers from the , ???
Hmm..
This may be difficult to ynderstand, but I have tried my best to explain ;)
Christopher Brandsdal

Jul 19 '05 #5

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

Similar topics

5
3397
by: Lars Behrens | last post by:
Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and planning. The web site will have a submission page for attendants of a congress. In a form the user will submit name, mailadress etc. and I plan to store the data in a list of dictionaries: People =
3
1767
by: faktujaa | last post by:
Hi, Currently im storing the connection info. in XML file on the C drive. the only problem with this is that anybody can open and check the database name. I know encryption can solve this problem but still im concerned whether this is the right place to store connection info as in earlier project that was in C++, we use to store the connection info. in registry but the problem with this approach is that your application becomes windows...
5
4137
by: Joakim Westman \(Elicit AB\) | last post by:
Hi! I have a page that generates a lot of HTML, and I am considering different solutions to constrain the amount of code that is sent back to the client. One thing I thought about is the viewstate which is fairly large for this application. Does anybody have any experience on storing viewstate in Session.
21
2963
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
5
1135
by: Rob | last post by:
Where is the best place to store database connection info in a vb.net program ? I do not want to "hard-code" a database name into my program. Where could I store and retrieve that information ? Also, could you point in the the right direction as to how one might do it ? Thanks
1
3404
by: rdemyan via AccessMonster.com | last post by:
I'm trying to implement a licensing scheme. There are three types of licenses: Trial - good for 30 to 60 days Interim - good for 1 year Fully Paid - no expiration Everything is working fine and I've even implemented a registration system where the users can upgrade by just receiving a code from me.
8
2559
by: Merk | last post by:
I'm looking for a safe and maintainable way to store connection string info (connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app); things like server name or IP address and database name. I need to provide the client application with this info for connecting to both a test SQL Server and a production server. I would prefer to NOT hard-code this info into the client application, and App.Config seems rather unsafe as the...
4
6955
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather than database, since often I do not know how much information users submit for things like item description or images URL paths. This information may be very short or very long. MS SQL Server requires a maximum field length to be set. Thus, if user enters 5 characters into 5000 character field,...
2
2178
by: Alex | last post by:
Hey Guys.. I'm just now starting to learn VB 2005, but I have a question that might help me in the long run. I hope to write applications which store user data, and without wanting the user to always have an MS SQL database (or other DB) on hand, is it possible to have VB 2005 store all data in XML files? It might be a substancial amount of data, like hundreds of records, but given these files are never edited manually, can XML handle...
8
2179
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that the user can edit those particular values and also that should be updated in the mysql database.kindly reply me as early as possible. Thanks
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.