日期:2014-05-18  浏览次数:20384 次

散分80!小弟提问!大伙来看看!不够+分!顶者有分!!!!!!
大概意思是这样的在数据表中有一个名称为:auto_browse_num   的字段,字段类型是int类型里面存的是访问次数的综合!
我在程序的类中需要写一段代码如果进入了此页那就在访问次数中更新一下数据库+1
============
操作类源码:
public   static   bool   Fwcs(   string   pid   )
{
SqlConnection   con   =   showclass.datacon.AutoCon();
con.Open();
SqlCommand   cmd   =   new   SqlCommand( "AutoPrice_Fwcs   "   +   pid,con);
cmd.CommandType   =   CommandType.StoredProcedure;
cmd.Parameters.Add( "@auto_browse_num ",SqlDbType.Int,4).Value   =   +1;
cmd.ExecuteReader();
con.Close();
return   false;
}
pid是数据表中的编号所以需要进参!
============
aspx.cs页面代码:
public   class   LooksAutomobile   :   System.Web.UI.Page
{
public   bool   Fw;
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
Fw   =   AutoColumns.Demonstration.LookedClass.Fwcs(   Request.QueryString[ "pid "].ToString()   );
}
}
============
存储过程如下:
CREATE   PROCEDURE   AutoPrice_Fwcs
@cxid   int,
@auto_browse_num   int
AS  
UPDATE   AutoPrice   SET  
[auto_browse_num]   =   @auto_browse_num
WHERE   [PriceID]   =   @cxid
GO
============
现在报错:
未能找到存储过程   'AutoPrice_Fwcs   40969 '。  
这是怎么回事?请大伙给指教一下!

------解决方案--------------------
up
------解决方案--------------------
是不是参数的问题
------解决方案--------------------
SqlCommand cmd=new SqlCommand( "存储过程名 ",con);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add( "@参数 ",SqlDbType.VarChar);
cmd.Parameters[0].Value=......

------解决方案--------------------
参数的问题

------解决方案--------------------
jiefenzuigao
------解决方案--------------------
我没有看出什么问题.
------解决方案--------------------
你可以这样做,先取出数据库中的最大值:select max(auto_browse_num) from table
然后在存储过程中传参数的时候,用最大值+1
------解决方案--------------------
up
------解决方案--------------------
帮顶!
------解决方案--------------------
问题出在:SqlCommand cmd = new SqlCommand( "AutoPrice_Fwcs " + pid,con);
==========================================================
SqlCommand cmd=new SqlCommand( "AutoPrice_Fwcs,con ");
另外,你这种增加访问次数的方法不怎么样啊
------解决方案--------------------
UP
------解决方案--------------------
你这样改
先改存储过程

CREATE PROCEDURE AutoPrice_Fwcs
@cxid int,
AS
declare @a int

select @a=auto_browse_num from AutoPrice where PriceID=@cxid
set @a=@a+1
UPDATE AutoPrice SET
[auto_browse_num] =@a WHERE [PriceID] = @cxid
GO

然后只要传一个参数过去就可以了
------解决方案--------------------
jf
------解决方案--------------------