Hi There,

I am fairly new to ASP.net and MS Access.
I am workin gon a site where i need to make a product catalogue.
The products can be maintained from an admin section. I Have designed and got the page ready for inserting new products. I am stuck at one place where i need to upload an image too for this product with the product detail i insert.
Can anyone help with how i can link the image that i upload to its right product details.
I know how to upload the image and store it in the folder. I want to know how to link the image in the product table with its respective product details.

Please help me with this.

Thanks

Create an 'Image' table in your DB

this could have something like:

ImageID (Primary Key)
ProductID (foreign key)
ImageUrl

store the path to the image in this table with the productID it relates to.

When use the product details you can pull the related image using the ProductID

Thank you.
But i may have many images to the same product. Can you help me with the code to store the image url in MS Access. I am sorry but i am very new to this and this is firsttime working in asp.net and MS access.

Thanks again for the help

you can still use the image table - just add each image url into the table along with the corresponding product id. You can then retrieve all the images from the table that match the given productID.

whats your code for inserting the product at the moment?

I am using the following codes for inserting data in product table

public void Button1_Click(object sender, EventArgs e)
    {
        
        string ConnString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Balaji.mdb";
        string query = "Select Count(*) From Products Where DesignNo = ? And ProductName = ?";
        int result = 0;
        using (OleDbConnection conn = new OleDbConnection(ConnString))
        {
            using (OleDbCommand cmd = new OleDbCommand(query, conn))
            {
                cmd.Parameters.AddWithValue("", DesignNo.Text);
                cmd.Parameters.AddWithValue("", Productname.Text);
                conn.Open();
                result = (int)cmd.ExecuteScalar();
            }
        }
        if (result > 0)
        {
            Literal1.Text = "Product Exists. Please Enter a new Product Name and New Design No.";

        }
        else
        {



            string SqlString = "Insert Into Products (DesignNo, CategoryID, ProductName, Quality, Rate1, Rate2, Availability, WashingInst) Values (?,?,?,?,?,?,?,?)";

            using (OleDbConnection conn = new OleDbConnection(ConnString))
            {

                using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
                {

                    cmd.CommandType = CommandType.Text;

                    cmd.Parameters.AddWithValue("DesignNo", DesignNo.Text);
                    cmd.Parameters.AddWithValue("CategoryID", DropDownList4.SelectedValue);
                    cmd.Parameters.AddWithValue("ProductName", Productname.Text);
                    cmd.Parameters.AddWithValue("Quality", Quality.Text);
                    cmd.Parameters.AddWithValue("Rate1", INRrate.Text);
                    cmd.Parameters.AddWithValue("Rate2", USDrate.Text);
                    cmd.Parameters.AddWithValue("Availability", Avail.Text);
                    cmd.Parameters.AddWithValue("WashingInst", Washingdet.Text);

                    conn.Open();

                    cmd.ExecuteNonQuery();

                    Response.Redirect("Product_view.aspx");

                }
            }
        }
    }

Now i Need to add pictures to the products. So i want to upload the pictures in a folder and link them to the product in the product table.
How i am searching for the same.
Also need to change the file name while uploading. Can anyone help me with tehe code.
I will be using the ASP.net File Upload control i guess

I have got the way to upload the images to Image table, but how do i get the image url in image table. I can get the Product ID, Image gets renamed and its new name is stored in the table with its id and product id. Now how do i retrive this back in the page. Can ayone help me with this...

I have got the way to get the image name in the access database and store the image file in a folder.
Now i want to display only the first image of the product in the main product page and when one clicks on the image it shows the complete details of the product.
Is there anyone to help me with this.. please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.