用sqlcommand对象怎么对sql存储过程中的参数进行变量传递呢?在线等!!!!
我定义一sqlcommand对象,commandtype属性设置为存储过程:StoredProcedure
dim sqlCom1 as new sqlcommand()
sqlcom.commandtype=StoreProcedure
sqlCom =new sqlcommand("cb_tj",sqlConn)
sqlCom1.Parameters.Add("@nf", SqlDbType.NVarChar)
sqlCom1.Parameters.Add("@yf", SqlDbType.NVarChar)
sqlCom1.Parameters("@nf").Value = Trim(nf_Pub)
sqlCom1.Parameters("@yf").Value = Trim(yf_Pub)
sqlconn.open()
sqlCom1.ExecuteNonQuery()
sqlConn.Close()
其中"cb_tj"是自己创建的存储过程,@nf,@yf是其中的二个参数,感觉程序没错,但一运行总有错误提示,什么原因呢????
cb_tj存储过程:
create procedure cb_tj
@nf nvarchar,
@yf nvarchar
as
select a.合计+b.合计+c.合计 应收电费合计,a.归属线别
from
(select sum(本月电表差数合计*倍数百分比) 合计,归属线别 from cb_tjprint where 年份=@nf and 月份=@yf
group by 归属线别 ) a join
(select sum(抄表电量) 合计, 线别 from cb_total where 年份=@nf and 月份=@yf
group by 线别 ) b on a.归属线别=b.线别
join (select sum(上行单耗*上行运量+下行单耗*下行运量
)合计 ,线别 from cb_fdjl where 年份=@nf and 月份=@yf
group by 线别) c on a.归属线别=c.线别
go