stored procedure - har jeg defineret forkert
Jeg har noget kode som enten inserter eller updater. Update virker, men insert virker ikke, med mindre jeg eksekverer det i min DB admin tool. OG JEG FATTER DET IKKE - kan i sige hvor det går galt? Er det måden jeg definerer mine vars på i C#?Min SP:
ALTER PROCEDURE [dbo].[highscore_save]
@name varchar(255),
@email varchar(255),
@score int,
@ip varchar(20)
AS
BEGIN
IF EXISTS(SELECT id FROM [highscore] WHERE name = @name AND email = @email)
BEGIN
UPDATE highscore SET score = (score + @score) WHERE name = @name AND @email = email;
END
ELSE
BEGIN
INSERT INTO [highscore] ([name],email,score,ip,dateCreated) VALUES (@name, @email, @score, @ip, GETDATE() );
END
END
GO
MIN C# kode:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnString"].ConnectionString);
conn.Open();
SqlCommand command = new SqlCommand("highscore_save", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@name", Request.Form["navn"]);
command.Parameters.AddWithValue("@email", Request.Form["email"]);
command.Parameters.AddWithValue("@score", Request.Form["score"]);
command.Parameters.AddWithValue("@ip", Request.ServerVariables["REMOTE_ADDR"].ToString());
Response.Write("&success=1&");
conn.Close();