0
我試圖使用visual studio 2010將一行添加到mysql數據庫表中,直到現在我還沒遇到問題。我不斷收到錯誤:當我使用帶參數的Insert Into語句時,出現致命錯誤
"Fatal error encountered during command execution."
表結構:
delimiter $$
CREATE TABLE `magazine_images` (
`image_id` int(11) NOT NULL AUTO_INCREMENT,
`MagazineKey` int(5) DEFAULT NULL,
`image_type` varchar(45) NOT NULL,
`image` blob,
`image_size` varchar(45) NOT NULL,
`image_ctgy` varchar(45) NOT NULL,
`image_name` varchar(50) NOT NULL,
PRIMARY KEY (`image_id`),
KEY `image_magazine` (`MagazineKey`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1$$
升C查詢:
string image = "INSERT INTO magazine_images (MagazineKey, image, image_type, image_size, image_ctgy, image_name) " +
"VALUES(@magkey, @image, @image_type, @image_size, @image_ctgy, @image_name)";
this.cmd = new MySqlCommand(putImage, this.con);
this.read = this.cmd.ExecuteReader();
this.read.Read();
this.cmd.Parameters.AddWithValue("@magkey", int.Parse(labelKey.Text));
this.cmd.Parameters.AddWithValue("@image", textBoxImageFile.Text);
this.cmd.Parameters.AddWithValue("@image_name", textBoxImageName.Text);
this.cmd.Parameters.AddWithValue("@image_type", comboBoxImageType.Text);
this.cmd.Parameters.AddWithValue("@image_ctgy", textBoxImageCategory.Text);
this.cmd.Parameters.AddWithValue("@image_size", labelImageSize.Text);
this.read.Close();
哦哇,我沒有注意到我執行後添加了參數。非常感謝你的支持。是的,當我由於某種原因複製代碼時,我將'putImage'更改爲'image'。我要睡覺。 此外,感謝您告訴我關於ExecuteReader,ExecuteNonQuery方法。我在今年夏天學習了C#,並且還在學習。 –