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
2 7423
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. -
void Button_Click(object sender, System.EventArgs e)
-
{
-
-
SqlConnection conJobs;
-
string strConString;
-
SqlCommand cmdInsert;
-
SqlParameter parmReturn;
-
-
if (IsValid)
-
{
-
strConString = "DataSource=localhost;database=jobsabc;User ID=jobs123;Password=cd546dc;";
-
-
conJobs = new SqlConnection(strConString);
-
cmdInsert = new SqlCommand("addUser", conJobs);
-
cmdInsert.CommandType = CommandType.StoredProcedure;
-
parmReturn = cmdInsert.Parameters.Add("@return", SqlDbType.Int);
-
parmReturn.Direction = ParameterDirection.ReturnValue;
-
-
cmdInsert.Parameters.Add("@username", txtUsername.Text);
-
cmdInsert.Parameters.Add("@password", txtPassword.Text);
-
cmdInsert.Parameters.Add("@firstname", txtFirstname.Text);
-
cmdInsert.Parameters.Add("@lastname", txtLastname.Text);
-
-
-
conJobs.Open();
-
cmdInsert.ExecuteNonQuery();
-
conJobs.Close();
-
-
if ((int)cmdInsert.Parameters["@Return"].Value == 0)
-
{
-
-
Response.Redirect("registeraccept.aspx");
-
}
-
-
if ((int)cmdInsert.Parameters["@Return"].Value == -1)
-
{
-
lblError.Visible = true;
-
}
-
}
-
}
-
-
The code for the stored procedure is given below.
-
-
CREATE procedure addUser
-
(
-
@username Varchar( 20 ),
-
@password varchar( 20 ),
-
@firstname varchar( 30 ),
-
@lastname varchar( 30 )
-
)
-
As
-
-
If Exists( SELECT ul_username FROM UserList
-
WHERE ul_username = @username )
-
BEGIN
-
RETURN -1
-
END
-
-
If Exists( SELECT ul_email FROM UserList
-
WHERE ul_email = @email )
-
BEGIN
-
RETURN -2
-
END
-
-
ELSE
-
INSERT UserList (
-
ul_username,
-
ul_password,
-
ul_firstname,
-
ul_lastname
-
-
) VALUES (
-
@username,
-
@password,
-
@firstname,
-
@lastname
-
)
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |