下载次数

kyoregain 2008-02-23 05:31:15
我写了一个记录下载次数的代码,但是不知道为什么不能把次数传到数据库里

我先在数据库里写的存储过程:

CREAT PROCEDURE [dbo].[Proc_updatedownloadtimes]
-- Add the parameters for the stored procedure here
(@fileID [nvarchar](50),
@downloadtimes [int])
AS UPDATE [file4]
SET [downloadtimes] = @downloadtimes
WHERE ([fileID] = @fileID)


c#里写的是

public void updatedownloadtimes(string fileID, int downloadtimes)
{
String ConnectionString = ConfigurationManager.ConnectionStrings["abcConnectionString"].ConnectionString;
SqlConnection cn = new SqlConnection(ConnectionString);
SqlCommand cmd3 = new SqlCommand("Proc_updatedownloadtimes", cn);
cmd3.CommandType = CommandType.StoredProcedure;
SqlParameter[] parameters = {
new SqlParameter("@fileID",SqlDbType.NVarChar,50),
new SqlParameter("@downloadtimes",SqlDbType.Int)};


parameters[0].Value = fileID;
parameters[1].Value = downloadtimes;


foreach (SqlParameter parameter in parameters)
{
cmd3.Parameters.Add(parameter);

}
try
{
cn.Open();
cmd3.ExecuteNonQuery();
cn.Close();

}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}

protected void Button1_Click(object sender, EventArgs e)
{
string fileID = Page.Request.QueryString["fileID"];
int downloadtimes = Convert.ToInt32(downloadtimesID.Text) + 1;
updatedownloadtimes(fileID, downloadtimes);
}

这里button1是一个按钮,我想问问为什么?
...全文
111 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shinaterry 2008-02-23
  • 打赏
  • 举报
回复
-_-!!! 郁闷! 3/4楼的请班竹删掉...
kyoregain 2008-02-23
  • 打赏
  • 举报
回复
谢谢大家,我是vs2005+sql2005,而且没有报错
shinaterry 2008-02-23
  • 打赏
  • 举报
回复
SqlCommand cmd3 = new SqlCommand("Proc_updatedownloadtimes @fileID, @downloadtimes", cn);
shinaterry 2008-02-23
  • 打赏
  • 举报
回复
[code=C#]SqlCommand cmd3 = new SqlCommand("Proc_updatedownloadtimes @fileID, @downloadtimes", cn);[code]
shinaterry 2008-02-23
  • 打赏
  • 举报
回复
试试这样:

[code=C#]SqlCommand cmd3 = new SqlCommand("Proc_updatedownloadtimes @fileID, @downloadtimes", cn);code]
shinaterry 2008-02-23
  • 打赏
  • 举报
回复
同意...

如果没有报错(有则贴出), 而且没具有与你相同的开发环境之下, 单单只看代码, 很难知道错误所在...

还是细心调试...

^o^
ice_frank 2008-02-23
  • 打赏
  • 举报
回复
不知有没有报错,如果没报错的话,看是否数据库连接、传入的数据是否正确
这个问题,我觉得你应该一步一步调试下就可以找到问题所在

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧