Upload picture while adding new product

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 лет назад
Why does nopCommerce not allow uploading pictures until the product has been saved?
14 лет назад
There are 2 things to remember in this situation:

when you want to add image : you 1) Browse the image file 2) You click on Upload

(When you click on Upload Button, the image gets saved in in the database)

Now coming back to your question : "Why does nopCommerce not allow uploading pictures until the product has been saved? "

because when you add product from your admin section

The moment you click on Save Button, that is the time when product ID gets generated for that product

So if you're trying to upload image before saving the product, the product ID has not generated yet and logically you're trying to connect image ID with Product ID (Which has not been generated yet) so obviously it will ask you to save the product first.

Hope it helps you to understand the logic
(Let me know if you have any confusions)
14 лет назад
I've worked with images in databases before.  All you have to do is add an output parameter to the query and use the  SCOPE_IDENTITY() function in MS SQL to return the Identity of the column.  It would look like this:

string insertProduct = "INSERT INTO Nop_Product (value, value, ...) VALUES ('value', 'value', '...') SET @ReturnID = SCOPE_IDENTITY()";

SqlConnection conn = new SqlConnection("ConnectionString");  //setup connection

SqlCommand cmd = new SqlCommand(insertProduct, conn);  //setup command

SqlParameter param = new SqlParameter("@ReturnID", SqlDbType.Int); //setup parameter
param.Direction = ParameterDirection.Output;

cmd.Parameters.Add(param);  //add parameter to command

cmd.ExecuteNonQuery(); //execute the command

int ProductID = (int)param.Value;  //this will bring back the newly added ProductID

I use this type of code all the time when doing transactions.  It works great.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.