使用输入输出存储过程数据接入 [英] data insert using input output stored procedure

查看:102
本文介绍了使用输入输出存储过程数据接入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用ASP.net C#中的Web应用程序。我有一个预约表,我需要使用存储过程将数据插入到表中。该表有几列,其中的第二列是一个计算列。存储过程设置为插入数据和插入后从第二列获取值。下面是code存储过程:

I am creating a web application using ASP.net C#. I have a booking form and I need to insert data into a table using a Stored Procedure. The table has several columns, out of which second column is a computed column. The Stored Procedure is set up to insert the data and fetch the value from the second column after insert. Below is the code for Stored Procedure:

    Create Procedure sp_InsertCashPooja
@FirstName varchar(100),
@LastName varchar(100),
@TelNo bigint,
@Star char(50),
@Rasi char(50),
@Gothram char(50),
@PDMID int,
@PayMode bit,
@PujaName char(50),
@DonateAmt decimal(19,2),
@RcptNo varchar(25) output

as

Begin

SET NOCOUNT ON;

BEGIN TRY

BEGIN TRANSACTION

    if @PujaName != 'DONATION'
    Begin

        INSERT INTO PoojaDetails (FirstName, LastName, TelNo, Star, Rasi, Gothram, PoojaDietyMasterID, PayMode) values (@FirstName,@LastName,@TelNo,@Star,@Rasi,@Gothram,@PDMID,@PayMode)

    End

    if @PujaName = 'DONATION'
    Begin

        DECLARE @isDonate int = 0;

        INSERT INTO PoojaDetails (FirstName, LastName, TelNo, Star, Rasi, Gothram, PoojaDietyMasterID, PayMode, isDonate, DonateAmount) values (@FirstName,@LastName,@TelNo,@Star,@Rasi,@Gothram,@PDMID,@PayMode, @isDonate, @DonateAmt)

    End

    Select @RcptNo = max(ReceiptNo) from PoojaDetails
    Return @RcptNo
COMMIT TRANSACTION

END TRY

BEGIN CATCH
    IF (@@TRANCOUNT > 0)

    ROLLBACK TRANSACTION

END CATCH

SET NOCOUNT OFF;


End

我想插入一个按钮的点击数据:我能计算出低于code ....

I would like to insert data on the click of a button: I was able to figure out the below code....

 protected void btnSave_Click(object sender, EventArgs e)
        {


            frmFirstName = txtFirstName.Text.Trim().ToUpper();
            frmLastName = txtLastName.Text.Trim().ToUpper();
            frmPhoneNo = Convert.ToInt32(txtPhoneNo.Text.Trim());
            frmNakshatra = Convert.ToString(cmbNakshatra.SelectedItem).Trim();
            frmRasi = Convert.ToString(cmbRasi.SelectedItem).Trim();
            frmGothram = Convert.ToString(cmbGothram.SelectedItem).Trim();
            frmPujaName = Convert.ToString(cmbPujaName.SelectedItem).Trim();
using (SqlConnection connection = new SqlConnection())
        {
            if (frmPayMode == "Cash")
            {
                if (frmPujaName == "DONATION")
                {
                    SqlDataAdapter CashAdapter = new SqlDataAdapter();

                    CashAdapter.InsertCommand = new SqlCommand("sp_InsertCashPooja", connection);
                    CashAdapter.InsertCommand.CommandType = CommandType.StoredProcedure;

请帮忙....我想捕捉返回RcptNo后来打算调用另一个ASPX页面,并使用查询字符串传递的价值。

Please help.... I want to capture the returning RcptNo and later intend to call another ASPX page and pass the value using a Query String.

感谢

推荐答案

使用简单的SqlCommand调用您的SP

Use simple SqlCommand for calling your SP

connection.Open();
var cmd = new SqlCommand("sp_InsertCashPooja", connection);
cmd.Parameters.AddWithValue("FirstName", frmFirstName);
// Add all the others parameters in same way
var id = (int)cmd.ExecuteScalar();
connection.Close();

这篇关于使用输入输出存储过程数据接入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆