ASP.NET中调用存储过程后,运行无错误,但数据库没有任何改变,请大家帮我看看
调用程序:
private void btnAssetSave_Click(object sender, System.EventArgs e)
{
SqlConnection conn=DB.createConnection ();
SqlDataAdapter da=new SqlDataAdapter() ;
da.SelectCommand = new SqlCommand ();
da.SelectCommand.Connection =conn;
da.SelectCommand.CommandText ="AssetPda";
da.SelectCommand .CommandType =CommandType.StoredProcedure ;
SqlParameter param1 = new SqlParameter("@code", SqlDbType.NVarChar);
param1.Direction = ParameterDirection.Input;
param1.Value = this.txtUsercode_asset .Text .ToString ();
SqlParameter param2 = new SqlParameter("@IMEI", SqlDbType.NVarChar);
param2.Direction = ParameterDirection.Input;
param2.Value = this.ddlUnassetPda .SelectedItem .Value ;
da.SelectCommand.Parameters.Add(param1);
da.SelectCommand.Parameters.Add(param2);
this.lbtip.Text ="分配成功!";
this.P_AssetPda.Visible =false;
}存储过程:
CREATE PROCEDURE dbo.AssetPda
(@code nvarchar(10),
@IMEI nvarchar(25))AS
begin transaction
SAVE TRANSACTION SAG
if (@@error<> 0)
goto failed
update TblAllHwUser set AssetPda=@IMEI where Employeecode=@code;
if (@@error<> 0)
goto failed
update TblPDA set status='使用中' where IMEI=@IMEI
if (@@error<>0)
goto failed
commit transaction
goto finished
failed:
rollback transaction SAG
finished: /* SET NOCOUNT ON */
RETURN
我的存储过程在数据库中运行是没有问题的,但是用前台调用的话就是没有效果,麻烦大家帮我看看。谢谢。
调用程序:
private void btnAssetSave_Click(object sender, System.EventArgs e)
{
SqlConnection conn=DB.createConnection ();
SqlDataAdapter da=new SqlDataAdapter() ;
da.SelectCommand = new SqlCommand ();
da.SelectCommand.Connection =conn;
da.SelectCommand.CommandText ="AssetPda";
da.SelectCommand .CommandType =CommandType.StoredProcedure ;
SqlParameter param1 = new SqlParameter("@code", SqlDbType.NVarChar);
param1.Direction = ParameterDirection.Input;
param1.Value = this.txtUsercode_asset .Text .ToString ();
SqlParameter param2 = new SqlParameter("@IMEI", SqlDbType.NVarChar);
param2.Direction = ParameterDirection.Input;
param2.Value = this.ddlUnassetPda .SelectedItem .Value ;
da.SelectCommand.Parameters.Add(param1);
da.SelectCommand.Parameters.Add(param2);
this.lbtip.Text ="分配成功!";
this.P_AssetPda.Visible =false;
}存储过程:
CREATE PROCEDURE dbo.AssetPda
(@code nvarchar(10),
@IMEI nvarchar(25))AS
begin transaction
SAVE TRANSACTION SAG
if (@@error<> 0)
goto failed
update TblAllHwUser set AssetPda=@IMEI where Employeecode=@code;
if (@@error<> 0)
goto failed
update TblPDA set status='使用中' where IMEI=@IMEI
if (@@error<>0)
goto failed
commit transaction
goto finished
failed:
rollback transaction SAG
finished: /* SET NOCOUNT ON */
RETURN
我的存储过程在数据库中运行是没有问题的,但是用前台调用的话就是没有效果,麻烦大家帮我看看。谢谢。
一般都是如下的顺序,你一开始就new SqlCommand()的话不是一个空的Command吗?
command = new SqlCommand(
"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
"WHERE CustomerID = @oldCustomerID", connection); // Add the parameters for the UpdateCommand.
command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");
SqlParameter parameter = command.Parameters.Add(
"@oldCustomerID", SqlDbType.NChar, 5, "CustomerID");
parameter.SourceVersion = DataRowVersion.Original; adapter.UpdateCommand = command;
定义两个变量。
将变量加入到Command中。
Command.exenonquery()
其实我建议使用“exec 存储过程名 参数1 参数2 等”
begin transaction
SAVE TRANSACTION SAG
update TblAllHwUser set AssetPda=@IMEI where Employeecode=@code;
update TblPDA set status='使用中' where IMEI=@IMEI
if (@@error<>0)
goto failed
commit transaction
goto finished
failed:
rollback transaction SAG
finished: