我有两个问题。
如何从存储过程中获取输出参数。
当我将值传递给存储过程时,我在DAL文件中出错,错误是
数据阅读器与指定的内容不兼容 'Form2290.usp_sup2290_upd_business_Result'。该类型的成员, 'ErrorNumber',数据读取器中没有相应的列 同名。
我的aspx.cs代码在
之下 Business objbusiness = new Business();
Businesses.Address objAddress = new Businesses.Address();
objbusiness.BusinessID = Convert.ToString(Session["BUSINESS_KEY"]);
if (editstate.Text.Trim() != "")
objAddress.State = editstate.Text.Trim();
else
objAddress.State = editddlstate.SelectedValue;
objbusiness.EIN = editein.Text.Trim();
objbusiness.Name = editname.Text.Trim();
if (changeaddress.Checked)
{
objbusiness.IsAddressChange = true;
}
else
{
objbusiness.IsAddressChange = false;
}
objAddress.AddressLine1 = editaddress.Text.Trim();
objAddress.AddressLine2 = editadd2.Text.Trim();
objAddress.City = editcity.Text.Trim();
objAddress.Country = editcontry.Text.Trim();
objAddress.Zip = editzip.Text.Trim();
if (updatemaster.Checked)
{
objbusiness.isMasterUpdate = true;
}
else
{
objbusiness.isMasterUpdate = false;
}
objbusiness.Remarks = remarks.Text.Trim();
objbusiness.BusinessAddress = objAddress;
BAL_F2290 updbusiness = new BAL_F2290();
Form2290.Form form = new Form2290.Form();
form.FormID = Session["Form_Key"].ToString();
objbusiness.UserID = Session["User_Key"].ToString();
var data = updbusiness.updreprocess(objbusiness, Session["Form_Key"].ToString());
我的BAL代码在
之下public DataTable updreprocess(Business objbusiness,string formkey)
{
try
{
objbusiness.EIN = Crypt.Encrypt(objbusiness.EIN);
DAL_F2290 result = new DAL_F2290();
return objDAL.updreprocess(objbusiness, formkey);
}
catch(Exception ex)
{
return null;
}
}
我的DAL代码位于
之下 internal DataTable updreprocess(Business objbusiness, string formkey)
{
string error = string.Empty;
DataTable details = new DataTable();
try
{
var objdbbusiness = new DB_Form_Entities();
ObjectParameter objparaerror = new ObjectParameter("RESULT", typeof(string));
ObjectResult<usp_sup2290_upd_business_Result> r = objdbbusiness.usp_sup2290_upd_business(1, objbusiness.Remarks, objbusiness.isMasterUpdate, formkey, objbusiness.BusinessID, objbusiness.UserID, objbusiness.EIN
, objbusiness.Name, objbusiness.IsAddressChange, objbusiness.BusinessAddress.AddressLine1,
objbusiness.BusinessAddress.AddressLine2, objbusiness.BusinessAddress.City,
objbusiness.BusinessAddress.State, objbusiness.BusinessAddress.Country, objbusiness.BusinessAddress.Zip, objparaerror);
if (details.Rows.Count > 0)
{
details = Convertor.Generic2DataTable<usp_sup2290_upd_business_Result>(r);
}
return details;
}
catch (Exception ex)
{
return null;
}
}
和我的存储过程
ALTER PROCEDURE [dbo].[usp_sup2290_upd_business]
(
@executive_id int,
@remarks varchar(500),
@isMasterUpdate BIT,
@PK_Form_key VARCHAR(36),
@PK_Business_key VARCHAR(36),
@FK_C_UC_user_key VARCHAR(36),
@tax_id VARCHAR(24),
@business_name VARCHAR(50),
@isAddressChange BIT,
@address1 VARCHAR(100),
@address2 VARCHAR(100),
@city VARCHAR(50),
@state VARCHAR(50),
@country VARCHAR(100),
@zip VARCHAR(20),
@RESULT BIT OUTPUT
)
AS
begin
BEGIN TRANSACTION tran_upd_business_submitted
BEGIN TRY
UPDATE [2290_Business_Submitted]
SET tin = @tax_id,
name = @business_name,
is_addr_change = @isAddressChange,
addr_line1 = @address1,
addr_line2 = @address2,
city = @city,
state = @state,
country = @country,
zip = @zip
WHERE FK_2290F_key = @PK_Form_key AND FK_C_B_key = @PK_Business_key AND FK_C_UP_key = @FK_C_UC_user_key
IF(@isMasterUpdate=1)
begin
UPDATE [C_Business]
SET [tin] = @tax_id,
[name] = @business_name,
[is_addr_change] = @isAddressChange,
[upd_dt] = GETDATE()
WHERE [PK_C_B_key] = @PK_Business_key
UPDATE C_Address
SET addr_line1 = @address1,
addr_line2 = @address2,
city = @city,
FK_CM_USS_cd = @state,
FK_CM_C_cd = @country,
zip = @zip
WHERE PK_C_A_key = (SELECT
FK_C_A_key
FROM C_Business
WHERE [PK_C_B_key] = @PK_Business_key)
end
COMMIT TRANSACTION tran_upd_business_submitted
SET @RESULT = 1
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION tran_upd_business_submitted
SET @RESULT = 0
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH
BEGIN TRY
declare @qry varchar(5000)
SET @qry = 'update [2290_Business_Submitted] set tin=' + @tax_id
+ ',name=' + @business_name
+ ',is_addr_change=' + CONVERT(varchar, @isAddressChange)
+ ',addr_line1=' + @address1
+ ',addr_line2=' + @address2
+ ',city=' + @city
+ ',state=' + @state
+ ',country=' + @country
+ ',zip=' + @zip
+ ' where FK_2290F_key=' + @PK_Form_key
+ ' and FK_C_B_key=' + @PK_Business_key
+ ' and FK_C_UP_key=' + @FK_C_UC_user_key
INSERT INTO c_log_support (executive, query, remarks)
VALUES (@executive_id, @qry, @remarks)
IF(@isMasterUpdate=1)
begin
SET @qry = 'UPDATE [C_Business] SET [tin] = ' + @tax_id
+ ',[name] = ' + @business_name
+ ',[is_addr_change] = ' + CONVERT(varchar, @isAddressChange)
+ ',[upd_dt] =' + CONVERT(varchar(10),GETDATE(),110)+' '+CONVERT(varchar(12),GETDATE(),114)
+ ' WHERE [PK_C_B_key] =' + @PK_Business_key
INSERT INTO c_log_support (executive, query, remarks)
VALUES (@executive_id, @qry, '[2290_Business_Submitted]')
SET @qry = 'update C_Address set addr_line1=' + @address1
+ ',addr_line2=' + @address2
+ ',city=' + @city
+ ',FK_CM_USS_cd=' + @state
+ ',FK_CM_C_cd=' + @country
+ ',zip=' + @zip
+ ',upd_dt='+CONVERT(varchar(10),GETDATE(),110)+' '+CONVERT(varchar(12),GETDATE(),114)
+ ' where PK_C_A_key=(select FK_C_A_key from C_Business where [PK_C_B_key] = ' + @PK_Business_key
INSERT INTO c_log_support (executive, query, remarks)
VALUES (@executive_id, @qry, '[2290_Business_Submitted]')
end
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH
end