473,388 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Stored procedure to update multiple table same time

parshupooja
159 100+
Hello ,

I am using asp.net C# SQL Server . I have form on asp.net page consists various fields.
field 1, field 2 ------ upto field 10
on click of submit button i need to save all information entered by user into table1, table2, table3 tables.
field 1 to field5 is new record in table1 whereas field 6, field 7 , field 8 will update some columns in table 2 and rest fields will be updated to table 3.

To acheive this I need to write Stored procedure which saves this information to tables. Please help
Aug 21 '07 #1
2 7423
bhar
37
Hi,

After you enter the data into the fields, user will press the button control. The code is based on C# 2005. You need to pass the values from the page as parameters to the stored procedure.
Expand|Select|Wrap|Line Numbers
  1. void Button_Click(object sender, System.EventArgs e)
  2. {
  3.  
  4. SqlConnection conJobs;
  5. string strConString;
  6. SqlCommand cmdInsert;
  7. SqlParameter parmReturn;
  8.  
  9.         if (IsValid)
  10.         {
  11.      strConString = "DataSource=localhost;database=jobsabc;User ID=jobs123;Password=cd546dc;";
  12.  
  13.            conJobs = new SqlConnection(strConString);
  14.             cmdInsert = new SqlCommand("addUser", conJobs);
  15.             cmdInsert.CommandType = CommandType.StoredProcedure;
  16.             parmReturn = cmdInsert.Parameters.Add("@return", SqlDbType.Int);
  17.             parmReturn.Direction = ParameterDirection.ReturnValue;
  18.  
  19.             cmdInsert.Parameters.Add("@username", txtUsername.Text);
  20.             cmdInsert.Parameters.Add("@password", txtPassword.Text);
  21.             cmdInsert.Parameters.Add("@firstname", txtFirstname.Text);
  22.             cmdInsert.Parameters.Add("@lastname", txtLastname.Text);
  23.  
  24.  
  25.             conJobs.Open();
  26.             cmdInsert.ExecuteNonQuery();
  27.             conJobs.Close();
  28.  
  29.         if ((int)cmdInsert.Parameters["@Return"].Value == 0)
  30.             {
  31.  
  32.                 Response.Redirect("registeraccept.aspx");
  33.             }
  34.  
  35.          if ((int)cmdInsert.Parameters["@Return"].Value == -1) 
  36.             {
  37.                 lblError.Visible = true;
  38.             }
  39.   }
  40. }
  41.  
  42. The code for the stored procedure is given below.
  43.  
  44. CREATE   procedure addUser
  45. (
  46.   @username Varchar( 20 ),
  47.   @password varchar( 20 ),
  48.   @firstname varchar( 30 ),
  49.   @lastname varchar( 30 )
  50.  )
  51. As
  52.  
  53. If Exists( SELECT ul_username FROM UserList
  54.            WHERE ul_username = @username ) 
  55. BEGIN  
  56. RETURN -1
  57. END
  58.  
  59. If Exists( SELECT ul_email FROM UserList
  60.            WHERE ul_email = @email ) 
  61. BEGIN  
  62. RETURN -2
  63. END
  64.  
  65. ELSE
  66.   INSERT UserList (
  67.     ul_username,
  68.     ul_password,
  69.     ul_firstname,
  70.     ul_lastname
  71.  
  72.      ) VALUES (
  73.     @username,
  74.     @password,
  75.     @firstname,
  76.     @lastname
  77.   )
Aug 22 '07 #2
parshupooja
159 100+
Hello bhar,

Thank You for reply but please read my doubt again.
I am trying to insert and update multiplte tables simultaneouly in single stored procedure
Aug 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alvin | last post by:
Hi All I need opinions on how to approach my task. I currently have 3 tables: the master table, the archive and a temp table. MASTER: has 3 fields ProductID and ProductNo and Released ARCHIVE:...
12
by: serge | last post by:
I have an SP that is big, huge, 700-800 lines. I am not an expert but I need to figure out every possible way that I can improve the performance speed of this SP. In the next couple of weeks I...
4
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: Godzilla | last post by:
Dear all, I have a challenge in hand and am not too sure how to accomplish this using stored procedure. I have a table containing about 3 fields, but I need to reorder/renumber a field value...
10
by: J. S. EDV | last post by:
Hello, I have got a little problem with stored procedures and C#. I have got a stored procedure which should only insert something in a table. For example: ALTER PROCEDURE DBO.PROC1 AS...
4
by: yin_n_yang74 | last post by:
I am new to SQL and SQL Server world. There must be a simple solution to this, but I'm not seeing it. I am trying to create a crystal report (v8.5) using a stored procedure from SQL Server...
5
by: byahne | last post by:
We just went live today with a production SQL Server 2005 database running with our custom Java application. We are utilizing the jTDS open source driver. We migrated our existing application...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...

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.