CreateConnectionString();
SqlCommand cmd = sqlConnection.CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "[MURL_InsertTokens]";
SqlParameter ParameterTokenID = new SqlParameter();
ParameterTokenID.ParameterName = "@TokenID";
ParameterTokenID.SqlDbType = System.Data.SqlDbType.Int;
ParameterTokenID.Direction = ParameterDirection.Input;
ParameterTokenID.Value = token;
cmd.Parameters.Add(ParameterTokenID);
SqlParameter ParameterToken = new SqlParameter();
ParameterToken.ParameterName = "@Token";
ParameterToken.SqlDbType = System.Data.SqlDbType.NVarChar;
ParameterToken.Direction = ParameterDirection.Input;
ParameterToken.Value = token;
cmd.Parameters.Add(ParameterToken);
return true;
存储过程:
ALTER PROCEDURE [dbo].[MURL_InsertTokens]
@TokenID int ,
@Token nvarchar(MAX)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF EXISTS (SELECT * FROM Tokens)
BEGIN
UPDATE Tokens SET Tokens = @Token WHERE TokenID = @TokenID
END
ELSE
BEGIN
INSERT INTO Tokens(Tokens) VALUES (@Token)
END
END
它返回 true,但我的数据没有被插入,我不知道为什么。