Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 11th, 2007, 09:38 AM
Authorized User
Join Date: Jan 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default converting and sending data problem

I want to send the FK from parent table to child table by getting the object with executescalar and converting the value of it to string and then to integer finally pass it to child table. The problem is that the converted data will lose the information. I mean it will become NULL.
This is how did I do:

insertCommand.CommandText = "SELECT @@IDENTITY AS P_ID ";

SqlParameter pIDParameter = new SqlParameter("@P_ID", SqlDbType.Int);
pIDParameter.Direction = ParameterDirection.ReturnValue;
object o = insertCommand.ExecuteScalar();
string s = o.ToString();
int P_ID = Int32.Parse(s);

what is the better way to the convertion or better way to pass it to child table?
Reply With Quote
  #2 (permalink)  
Old March 11th, 2007, 02:13 PM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts

The FK (Foreign Key) in the Parent Table IS the PK (Primary Key) in the Child Table, which is created at the Database Design Phase. If this is not done, then you MUST create the RELATIONSHIP between the Parent Table and the Child Table first.

More detail information can be found in Wrox's Beginning ASP.NET Databases Using VB.NET, Defining Relationships between DataTable Objects, p 155.

Hope this helps.

Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
Reply With Quote
  #3 (permalink)  
Old March 24th, 2007, 06:38 AM
Authorized User
Join Date: Mar 2007
Location: Beijing, Beijing, China.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam

You can use "DataRelation" object to create relationship between parent table and child table...of course you hafta fill DataSet with tables with DataAdapter object.
for example:Parent table:Order[primary key:"OrderID"] Child table:OrderDetail[foreign key:"OrderID"]
you can create bond between them like this: DataRelation orderRel=thisDataSet.Relations.Add("orderbond",thi sDataSet.Tables["Order"].Colums["OrderID"],thisDataSet.Tables["OrderDetail"].Colums["OrderID"]);
then use "foreach" statement..."OrderID" in Parent Table will be automatically passes to Child Table:
 for each(DataRow orderRow in thisDataSet.Tables["Order"].Rows)
   ....//parent table processing
    foreach(DataRow orderDetailRow in orderRow.GetChildRows(orderRel) )
    .....//Child table processing
sometimes .GetParentRows can also come into handy.
Hope this can help.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in e-mail structure sending data from data tiawebchd General .NET 3 May 5th, 2008 08:07 AM
Converting an XML data island to 2 arrays NeilAtWork Classic ASP XML 0 April 14th, 2004 10:38 AM
Converting int64 data type in VB6 yeeck VB How-To 1 December 9th, 2003 10:13 PM
Converting int64 data type in VB6 yeeck Beginning VB 6 0 November 27th, 2003 11:32 PM

All times are GMT -4. The time now is 07:03 PM.

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