下载次数
我写了一个记录下载次数的代码,但是不知道为什么不能把次数传到数据库里
我先在数据库里写的存储过程:
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是一个按钮,我想问问为什么?