p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ADO.NET (http://p2p.wrox.com/forumdisplay.php?f=109)
-   -   Sample code needed for Professional ADO.NET with VB .NET (http://p2p.wrox.com/showthread.php?t=72629)

hughveal February 7th, 2009 06:47 PM

Sample code needed for Professional ADO.NET with VB .NET
 
I have this book but could not find the sample code. Could someone e-mail it to me or tell me where to find it?

jminatel February 7th, 2009 08:04 PM

I think you are going to be out of luck unless you can find one of the authors who has this code. In 2003, APress acquired this book and many others from Wrox's former owners. Up until a few months ago, APress distributed the code. A few months ago, they stopped distributing the code for all of the Wrox books they own the rights to. We are not allowed to distribute their code.

They other option would be to return that old book and buy a current actual Wrox book on a current .NET version. That old book is .NET 1.0 era. Our 2 current Wrox ADO.NET books are:
Professional ADO.NET 2: Programming with SQL Server 2005, Oracle, and MySQL
and
Professional ADO.NET 3.5 with LINQ and the Entity Framework
and we have all the code you need for them.

Hope this helps.

slake June 29th, 2009 06:37 PM

Foreign key conatraint in database
 
Hi
I have 2 tables connected to each other and when i try to insert data int them from a vb form the foreign key relationship wont hold. Their respective primary keys are identity columns .
when data is inserted in the vb form the primary keys for both tables are generated.Foreign keys wont show.
I have created a data table with all the columns defined as well as the foreign key constraints but still nothing happens.

If anyone has dealt with a similar problem please advice as im reallly desperate to get this working and dont know what to do.

Please provide any code examples you might have as im new at dealing with programs and posting to forums.

Thanks in advance

peace95 June 30th, 2009 03:18 AM

slake:
It would be very helpful for you to show your two tables with the Primary Key(s) and Foreign Key(s) identified. Without seeing the two tables, I am making the suggestion:
  • The ONLY way for two tables to have identical keys, in a RDMS (Relational Database Management System, is for TableA to have a Key identified as the Primary Key i.e. TableA (A_ID PK, Anext). and a TableB(B_ID PK, Bnext, A_ID FK). Note: Primary Key in Table is the Foreign Key in TableB. It is this relationship, 1-to-many, that the Primary Key and Foreign Key constraints will hold true for adds, inserts, updates and Cascade deletes.
Hope this helps. (This is the second attempt of responding to this thread)

slake June 30th, 2009 03:54 PM

FOREIGN KEY NOT INPUT IN TABLE FROM VB.NET
 
hi there
Really gald you could answer so promptly. This is the scenario

Cust(C_id,CName,Address) , Book(B_id,Title,Author,C_id). Now these are my two table. I am inserting data into from my form in VB. I do not have any text boxes for the primary keys as they are both identity columns. When i insert the CName,Address then Title,Author from the text boxes in VB the info is saved and primary keys for both tables created.
However. I need to have the Primary key of the Cust table automatically inserted into the Book table as a foreign key. For example

Cust(1,J.Smith,45 london str) Book(11,The drive,M.Andrews,1). In this eample i know the the primary keys will auto generate when the data in inserted but 1 will not appear as a foreign key in Book unless i go back into the table and manually insert it. In my case i need to create some from of function to insert it for me everytime insert data into my tables. My user needs to only enter the required data and not bother about primary or foreign keys . I read about triggers that can be created in the database. Im not sure if this will work and if it does how do i write one(Please advise with an example) or if there is any other way of doing it.Please advise.

Thanks again in advance. i appreciate the help.

Kind regards

Slake

slake June 30th, 2009 06:13 PM

foreign key works but other data wont appear
 
Hi
I have created the trigger for my problem but then when i insert it all the other columns wont appear. Exampl

Student(studid,name,address) course(cid,coursename,date,stuid)
studid and cid are primary keys in there respective tables and forign key (studid) in course.

when i insert the vales in for everything except the primary and foreign key. all vales in the parent(student) table are generated.The child table will generate the first column with the foreign key and then another column without a foreign key.
So for every single parent column i generate 2 columns of the child table. Each having half of what i want. I need all the data to be insert in the same column


[CREATE TRIGGER TG_INS_STUDENT

ON dbo.STUDENT
FOR
INSERT
AS
BEGIN

INSERT INTO dbo.COURSE(STUDID)
SELECT STUDID FROM INSERTED
END]

please help me rectify it if you can i came so close.Look forwaard to hearing from you.

peace95 July 1st, 2009 05:00 AM

FOREIGN KEY NOT INPUT IN TABLE FROM VB.NET
 
Slake:

Thanks for the detail. One of your problems is due to the fact the relationship is not correct. What if the book is read, or bought by more than one Customer? In my opinion, the relationship between your Customer and your Book tables are many-to-many. You need a junction table:
Code:


CustTbl( C_id, CName, CAddress)---<CustBkTbl(CusBkID,C_id,B_id)>----BkTbl(B_id,....)
 
In the Book Table I removed the C_id and placed it in the junction table, CustBkTbl. The junction allows for the Customer to buy/read 1 or more books and it allows for the 1 or more Books to be read/bought by more than one Customer. The -----< & >----- indicates the relationships between the 3 tables.

Another situation I see in your Book Table is with the Author in that you may have more than 1 author per book....as in many WROX books, for example. To rectify that build the following::
AuthorTbl (authorID, author name) and AuthorBookTbl(aubkID, authorID,B_id), which is the junction table for Author and Book, the BkTbl(B_id,Title, ISBN).

Remember: "....The KEY is the KEY', from 70's movie Jumpin' Jack Flash

Hope this hellps.

peace95 July 1st, 2009 05:29 AM

foreign key works but other data wont appear
 
Slake:

You need to use the junction table between your Student Tasble or Entity and the Course Table or Entity. Remember to remove the Student ID from the Course Table. Follow instructions in previous response.

I forgot to mention, the tables on the right and left of the junction table MUST exist or be defined in the database BEFORE defining the junction table, the one in the middle,. Also in your forms you can use the Book, Author, Customer and Course Tables as LOVs after you populate them.

Redefine your RDBMS schemes...... Yes you are very close.....Don't Give Up!!

Hope This Helps.

slake July 1st, 2009 06:00 PM

foreign key constraint in sql
 
Hi Peace
Thanks for the helpon breaking the tables down. That i have done but i still need to auto generate the foreign keys of these relationships automatically. In ms sql i manually insert them as the primary keys are auto generated. I tried to write an insert trigger which did not work as i expected though it auto generated the foreign key but after the original data was inserted.

Do you know how to resdolve this issue please. If so let me know.I will be so greatful

Kind Regards

Slake

peace95 July 1st, 2009 09:01 PM

foreign key constraint in sql
 
Slake:
It sounds as if the problem or problems are in the Database Tables. Did you define the relationships between the tables? If not, this MUST be done. Is the RDBMS Oracle or MS SQL? I thought it was Oracle. Let me know.


All times are GMT -4. The time now is 06:12 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.