0

I'm trying to insert some data into my MySql Database using the .NET connector.

My stored procedure is as follows:

CREATE PROCEDURE `spr_StoreMoveData2`(IN `@characterID` INT, IN `@moveName` VARCHAR(1000), IN `@validBlocks` VARCHAR(50), IN `@damage` VARCHAR(500), IN `@stun` VARCHAR(500), IN `@cancelAbility` VARCHAR(50), IN `@framesStartup` VARCHAR(500), IN `@framesActive` VARCHAR(500), IN `@framesRecovery` VARCHAR(500), IN `@framesAdvOnHit` VARCHAR(500), IN `@framesAdvOnBlock` VARCHAR(500), IN `@additionalNotes` VARCHAR(5000))
    LANGUAGE SQL
    NOT DETERMINISTIC
    MODIFIES SQL DATA
    SQL SECURITY DEFINER
    COMMENT 'test'
BEGIN
INSERT INTO movedata 
(characterid, movename, validblocks, damage, stun, supermetergain,cancelability, framesStartup, framesActive, framesRecovery, framesAdvOnHit, framesAdvOnBlock, AdditionalNotes) 
VALUES 
(@characterID, @moveName, @validBlocks, @damage, @stun, @superMeterGain, @cancelAbility, @framesStartup, @framesActive, @framesRecovery, @framesAdvOnHit, @framesAdvOnBlock, @additionalNotes);
END

Which appears to save fine.

My .NET code is as follows:

 using (MySqlConnection conn = new MySqlConnection())
                {
                    conn.ConnectionString = ConfigurationManager.AppSettings["connectionString"].ToString();
                    conn.Open();

                    MoveData move1 = lmd[0];

                    MySqlCommand cmd = new MySqlCommand("spr_StoreMoveData", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("CharacterID", move1.CharacterID);
                    cmd.Parameters.AddWithValue("movename", move1.MoveName);
                    cmd.Parameters.AddWithValue("validblocks", move1.ValidBlocks);
                    cmd.Parameters.AddWithValue("damage", move1.Damage);
                    cmd.Parameters.AddWithValue("stun", move1.Stun);
                    cmd.Parameters.AddWithValue("supermetergain", move1.SuperMeterGain);
                    cmd.Parameters.AddWithValue("cancelability", move1.CancelAbility);
                    cmd.Parameters.AddWithValue("framesstartup", move1.Frames_Startup);
                    cmd.Parameters.AddWithValue("framesactive", move1.Frames_Active);
                    cmd.Parameters.AddWithValue("framesrecovery", move1.Frames_Recovery);
                    cmd.Parameters.AddWithValue("framesAdvOnHit", move1.Frames_AdvantageOnHit);
                    cmd.Parameters.AddWithValue("framesAdvOnBlock", move1.Frames_AdvantageOnBlock);
                    cmd.Parameters.AddWithValue("additionalNotes", move1.AdditionalNotes);

                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    cmd = null;
                }

If I use this, or if I use the following test query

call spr_StoreMoveData (1, '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1')

The error "Column 'CharacterID' cannot be null" appears. I set the columns to allow null values and a row will be inserted with all null values. I'm slightly perplexed.

I've tried looking at all the answers on the web, but I appear to be missing some syntax subtlety. Can anyone help?

4

1 回答 1

1

您的语句使用@superMeterGain,您的过程没有作为参数。因此,您正在设置和使用您的程序不知道的参数。将它添加到存储过程的参数列表中,它应该可以工作。

于 2013-05-23T22:54:46.543 回答