asp.net 执行创建proc的问题,关键字报错!!
string proc_tran = @"create proc proc_testtrans@isupd int output,
@ectype varchar(20),
@val varchar(10),
@empid nvarchar(64),
@y varchar(10) ,
@m varchar(10)
as
declare @err int
declare @updateSql varchar(8000)
set @err = 0
set nocount on
begin transaction updRecordUser
declare @cnt int
select @cnt = Count(*) from TB_RecordUser where EmpID = @empid and [Year] = @y and [Month]= @m
set @err = @err + @@error
if(@err <> 0 )
goto ErrMsg
if(@cnt = 0)
begin
declare @maxCnt int
select @maxCnt = max(id) from TB_RecordUser
set @maxCnt = @maxCnt +1
insert into TB_RecordUser(id,EmpID,[Year],[Month],Chidao,Zaotui,Weidaka,Bingjia,Kuanggong,Shijia) values
(@maxCnt,@empid,@y,@m,0,0,0,0,0,0)
set @err = @err + @@error
if(@err <> 0 ) goto ErrMsg
end
set @updateSql = 'update TB_RecordUser set '
if(@ectype = 'chidao') set @updateSql = @updateSql + ' Chidao = Chidao+'+@val
else if(@ectype = 'zaotui') set @updateSql = @updateSql + ' Zaotui = Zaotui+'+@val
else if(@ectype = 'weidaka') set @updateSql = @updateSql + ' Weidaka = Weidaka+'+@val
else if(@ectype = 'bingjia') set @updateSql = @updateSql + ' Bingjia = Bingjia+'+@val
else if(@ectype = 'kuanggong') set @updateSql = @updateSql + ' Kuanggong = Kuanggong+'+@val
else set @updateSql = @updateSql + 'Shijia = Shijia'+@val
set @updateSql = @updateSql + ' where EmpID = '+@empid+' and [Year] = '+@y+' and [Month]='+ @m
exec (@updateSql)
set @err = @err + @@error
if(@err <> 0) goto ErrMsg
else
begin
set @isupd = @err
commit tran updRecordUser
end
ErrMsg:
set nocount off
if(@@trancount = 1)
rollback tran updRecordUser
";
using (SqlConnection con = TB.General.DBConnection.GetConn(TB.General.DBName.A1))
{
con.Open();
SqlCommand cmmd = new SqlCommand(proc_tran,con);
cmmd.Parameters.Add("@empid", SqlDbType.NVarChar, 64).Value = empid;
cmmd.Parameters.Add("@y", SqlDbType.VarChar).Value = year;
cmmd.Parameters.Add("@m", SqlDbType.VarChar).Value = month;
cmmd.Parameters.Add("@val", SqlDbType.VarChar, 10).Value = val;
cmmd.Parameters.Add("@ectype", SqlDbType.VarChar).Value = et.ToString();
SqlParameter spa = new SqlParameter("@isupd", SqlDbType.Int);
spa.Direction = ParameterDirection.Output;
cmmd.Parameters.Add(spa);
cmmd.ExecuteReader();
}
最后的执行结果是 procedure 附近有错误。
存储过程没有问题,我保存到sql中在执行就没有问题,在网上看了下,应该是把CREATE PROCEDURE这个语句不能和别的执行语句放到一个批处理中,但是,如果sql中不存在这个proc 我必须要先创建它,才能执行它。
以我现在这样的形式,怎么才能让这个sql语句执行呢。
求教了。!! --------------------编程问答-------------------- 你先把存储过程在数据库中创建好
然后在前台调用存储过程不就行了。。。
补充:.NET技术 , ASP.NET