Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2009, 02:55 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using store Procedure to insert in 2 tables

Hi,

I need a store procedure that will take 2 parameters Name & age. It will be entered in 2 tables namely employee - will contain Name & employee_details - will contain age. employee is the main table which has a identity column empID as Primary key & employee_detail table is the detail table with empID as Foreign Key.

Now what would be the code for my store procedure if I have to insert 2 values - Name & Age for employees from a Asp.Net page using this store procedure.


Urgent Pls help !!!
 
Old September 28th, 2009, 07:17 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the following link for examples:
http://www.csharpfriends.com/Article...x?articleID=78
http://www.dotnetspider.com/forum/39...rocedures.aspx

Example:
Code:
string username = ... // get username from user
string password = ... // get password from user
SqlConnection conn = new SqlConnection("Data 
Source=localhost;Database=MyDB;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Username", SqlDbType.VarChar).Value = username;
command.Parameters.Add("@Password", SqlDbType.VarChar).Value = password;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();
You can write SP which will accept the required parameters and insert data in one or more tables.
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Store Procedure For Attendance prasanta2expert SQL Server 2000 4 July 5th, 2012 03:10 AM
Store procedure help... RinoDM SQL Server 2000 7 August 11th, 2008 07:09 PM
Store procedure help ??? RinoDM SQL Server 2000 8 May 1st, 2008 03:03 PM
store procedure if else problem krshekhar SQL Language 0 February 20th, 2008 05:31 AM
Store Procedure sureshyuga SQL Server 2000 0 May 18th, 2007 01:49 AM





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