this is new code:
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("Downloadurl_insert", conn))
{
foreach (GridViewRow row in GridView1.Rows)
{
string ipAddress;
ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == "" || ipAddress == null)
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
string name = (row.FindControl("LblName") as Label).Text;
_cmd.Parameters.AddWithValue("@downloadTitle", name);
_cmd.Parameters.AddWithValue("@url", "~/downloads/" + name + ".rar");
_cmd.Parameters.AddWithValue("@DownloadToken", GetDownloadToken(10));
_cmd.Parameters.AddWithValue("@IpAddress", ipAddress);
_cmd.Parameters.AddWithValue("@Hits", "0");
_cmd.Parameters.AddWithValue("@Downloaded", "false");
conn.Open();
_cmd.ExecuteNonQuery();
conn.Close();
}
}
}
And SP:
ALTER PROCEDURE [dbo].[Downloadurl_insert]
@downloadTitle NVARCHAR(60),
@url NVARCHAR(60)
,@DownloadToken NVARCHAR(60)
,@hits NVARCHAR(60)
,@Downloaded NVARCHAR(60)
,@IpAddress VARCHAR(50)
as
begin
insert into Download(downloadTitle,url,DownloadToken,ExpiryDate,hits,Downloaded,IpAddress)
values(@downloadTitle,@url,@DownloadToken,DATEADD(DAY,2,GETDATE()),@hits,@Downloaded,@IpAddress)
end
but I don't know why this error happen:
Procedure or function Downloadurl_insert has too many arguments specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function Downloadurl_insert has too many arguments specified.
Source Error:
Line 519: _cmd.Parameters.AddWithValue("@Downloaded", "false");
Line 520: conn.Open();
Line 521: _cmd.ExecuteNonQuery();
Line 522: conn.Close();
Line 523: }
|