Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everybody,

 

I am creating my first SQL-tables, using the server explorer of

VB.NET.

I made tables, one is named companies, the other contacts.

Both have a ID field, in INT-format.

In companies, only, this is a primairy key.

I have made a relationship between the ID's of the 2 tables.

 

No errors sofar.

 

But when I enter a value in one of the tables, leaving the

autonum blank(ofcaurse), then it does not make a autonumber

(or auto increment).

 

Also I get the error:

Cannot insert the value NULL into colomn 'id-company', table

'test4.dbo.tblCompany';colomn does not allow nulls.INSERT fails.

The statement has been terminated.

 

 

What do I have to adjust in the settings, to create a auto-increment?

 

 

 

 

Best regards,

 

Reinier Domsdorf :D

Posted

Hello Robby,

 

Thank you for the reply,

it was exactly what I needed!

 

Robby, I am aware of the basics of relationships

between DB's (one-to-many, primairy key,autonum),

I have created numerus tables and relations in MS access

before.

 

Still, I have a question,

 

 

Can you tell me how these autonumbers work,

in the SERVER EXPLORER, according to another

database related to the database wich held the

primairy key?

 

I mean, When I enter a string in a field,then in the

DB with a primairy key a autonum is generated,

just as you decribed in your reply.

Now, how do you make the "connection" in the

other database, is this only possible in a form,

on wich both DB's are visible, or is there in the

server explorer an other way of showing these

2 DB's the same time.

 

Example:

In table tblCompany I enter "Microsoft USA",

in the field ComanyName.

The autonum is then created as, lets say, 22

in the field ID-Company.

 

I have a second table, tblContacts, wich helds

all the Contactpersons.

Here I would like to add "Bill" in the field ContName.

 

HOW DOES THE TABLE CONNECT TO "MICROSOFT USA"?????

 

In my opinion this only can ne done while those 2 table

are visible at the same time...how, that is still a mistery

for me...

 

 

 

Best regards,

 

Reinier:D

  • Moderators
Posted

In tblContacts add a column named lets say company_id, this would be your FK (foreign key) you would enter 22 in this column. This will work without any further action, however you can take it to the next step and place constraints in place so that no one can enter an invalid ID into company_id. These constraints can be done with scripts in Query Analyzer or Enterptise Manager, I'm not sure if it can be done with VS.NET IDE (Actually a script can be run from a batch file too).

 

Before you place constraints in your DB you may want get familiar with the rest of your application first.

Visit...Bassic Software
Posted

Dear Robby,

 

I already placed a field called ID-Company, and I already made

a FK_tblCont_tblCompany, wich decribes the relation between

these2 tables.

I also can see a "unique contraint", what ever that may be.

 

You said "this would be your FK (foreign key) you would enter 22 in this column"

 

That is exactly my question, is this the way to make this work,

must I manually input the value, or is there a other way,

where both tables are on the screen..?

(In access for instance this done on the way that both

tables are present in the form, and the form is linkt to both

tables or query).

 

Well, maybe I am not familiar enough indeed, and maybe

when I studied some more, this quastion will be answered...

Thanks anyway.

 

 

Best regards,

 

reinier :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...