我正在轉換一個網上商店系統到另一個系統與C#。這是從DB到DB之間的一些轉換。C#雙入MySql數據庫雙重不工作
我有這樣的代碼在C#:
Double proPriceTmp = Double.Parse(productPrice);
Double realPrice = ((proPriceTmp/121) * 100);
string insertProduct = "INSERT INTO `" + ocPrefix + "product` (`product_id`, `model`, `quantity`, `stock_status_id`, `image`, `manufacturer_id`, `shipping`, `price`, `tax_class_id`,`date_available`, `weight`, `weight_class_id`, `length`, `width`, `height`,`length_class_id`,`subtract`,`minimum`,`sort_order`,`status`,`date_added`,`date_modified`,`viewed`) VALUES ('" + product_id + "', @param_model, '" + product_quantity + "', '" + stock_status_id + "', '" + image + "', '" + manufacturer_id + "', '" + shipping + "', '" + realPrice + "', '" + numericUpDown1.Value + "', '" + date_available + "', '" + product_weight + "', '" + weigth_class_id + "', '" + product_length + "', '" + product_width + "', '" + product_height + "', '" + length_class_id + "', '" + substracting + "', '" + minimum + "', '" + sort_order + "', '" + status + "', '" + product_created + "', '" + product_modified + "', '" + viewed + "')";
MySqlCommand cmdInsertProduct = new MySqlCommand(insertProduct, connOc);
cmdInsertProduct.CommandText = insertProduct;
cmdInsertProduct.Parameters.AddWithValue("@param_model", product_name);
cmdInsertProduct.ExecuteNonQuery();
cmdInsertProduct.Dispose();
這是價格變量(調試器感謝)值:
productPrice = "1,20000";
proPriceTmp = 1.2;
realPrice = 0.99173553719008256;
但在DB價格0.0000
。我已經嘗試過手工插入信息,而且工作(用這麼長的數字),所以這應該工作。
表看起來是這樣的:
CREATE TABLE `oc_product` (
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`model` varchar(64) NOT NULL,
`sku` varchar(64) NOT NULL,
`upc` varchar(12) NOT NULL,
`ean` varchar(14) NOT NULL,
`jan` varchar(13) NOT NULL,
`isbn` varchar(13) NOT NULL,
`mpn` varchar(64) NOT NULL,
`location` varchar(128) NOT NULL,
`quantity` int(4) NOT NULL DEFAULT '0',
`stock_status_id` int(11) NOT NULL,
`image` varchar(255) DEFAULT NULL,
`manufacturer_id` int(11) NOT NULL,
`shipping` tinyint(1) NOT NULL DEFAULT '1',
`price` decimal(15,4) NOT NULL DEFAULT '0.0000',
`points` int(8) NOT NULL DEFAULT '0',
`tax_class_id` int(11) NOT NULL,
`date_available` date NOT NULL,
`weight` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`weight_class_id` int(11) NOT NULL DEFAULT '0',
`length` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`width` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`height` decimal(15,8) NOT NULL DEFAULT '0.00000000',
`length_class_id` int(11) NOT NULL DEFAULT '0',
`subtract` tinyint(1) NOT NULL DEFAULT '1',
`minimum` int(11) NOT NULL DEFAULT '1',
`sort_order` int(11) NOT NULL DEFAULT '0',
`status` tinyint(1) NOT NULL DEFAULT '0',
`date_added` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`date_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`viewed` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`product_id`)
) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;
因此,沒有任何人知道這是爲什麼不工作像它應該做的?即使是在朝着正確的方向輕輕一推,就足夠了...
編輯
至於質疑,這裏是insertProduct
值。正如你所看到的,是價格那裏的權利...
"INSERT INTO `oc_product` (`product_id`, `model`, `quantity`, `stock_status_id`, `image`, `manufacturer_id`, `shipping`, `price`, `tax_class_id`,`date_available`, `weight`, `weight_class_id`, `length`, `width`, `height`,`length_class_id`,`subtract`,`minimum`,`sort_order`,`status`,`date_added`,`date_modified`,`viewed`) VALUES ('51', @param_model, '999999999', '7', 'data/old/letter_trein.jpg', '0', '1', '0,991735537190083', '11', '2013-06-09', '600,000', '1', '0,000', '0,000', '0,000', '1', '0', '0', '0', '1', '2013-01-09 12:26:02', '2013-10-24 10:23:47', '0')"
哇,這一切都沒有使用參數化查詢? – Steve
'insertProduct'的值是什麼? –
您的意思是插入成功,沒有錯誤,但只有價格字段保持0? – LINQ2Vodka