string ProductType = comboBoxProductType.Text;
string ProductID = "Select ProductID from Productinformation where Name = '" + ProductType + "'";
string query = "Insert into CustStoreProd (ProductID) VALUES (?ProductID)";
MySqlCommand cmd = new MySqlCommand(query, mySQLconnection);
cmd.Parameters.AddWithValue("?ProductID", "ProductID");
cmd.ExecuteNonQuery();
我想插入从选择查询“产品ID”的值插入值,我测试串ProductID
作品,如果我只是插入一个cmd.Parameters.AddWithValue("?ProductID", "1");
,它也能工作,但是当我把productID
纳入parameters.addwithvalue
,它不起作用。它只是整个项目的一个功能,所以我创建了外部的mysql数据库连接。SELECT查询
您可以只使用INSERT INTO ... SELECT。但是你应该参数化你的'WHERE'子句以避免SQL注入。 –