Developer forum

Forum » Development » Creating Products programatically

Creating Products programatically


Reply

Hi, I'm trying to create a custom import script which will allow our customer to

import products to the Dynamicweb ecommerce based on an excel sheet.

I've tried to create the products programatically but I keep getting an sqltype exception:

 

Product save : System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at Dynamicweb.eCommerce.Products.Product.Save(String ProductID, String ProductVariantID)

 

what could be causing this exception?

 

Here's my code:

 

DataSet ds = FonqiCode.NET.Converter.ExcelToDataSet(Server.MapPath("/Files/" + excelPath), "Produktark");

            foreach (DataRow d in ds.Tables[0].Rows)
            {
                if (string.IsNullOrEmpty(d["VARENAVN"].ToString()))
                    return;
                if (!string.IsNullOrEmpty(d["GROUP"].ToString()))
                {
                    currentGroup = new Dynamicweb.eCommerce.Products.Group(d["GROUP"].ToString());
                }

                Product product = new Product();
                product.ID = d["PRODUKTID"].ToString();
                product.Name = d["VARENAVN"].ToString();
                product.LongDescription = d["BRØDTEKST"].ToString();
                product.ImageSmall = "/Files/Billeder/Ecom/Products/" + currentGroup + "/" + product.ID + "/imageSmall/" + d["SMALLIMAGES"].ToString() + ".png";
                product.ImageMedium = "/Files/Billeder/Ecom/Products/" + currentGroup + "/" + product.ID + "/imageMedium/" + d["MEDIUMIMAGES"].ToString() + ".png";
               
                product.ProductFieldValues = new ProductFieldValueCollection();
                ProductFieldValue impargs = new ProductFieldValue(importantArgs, d["IMPORTANTARGUMENTS"].ToString());
                product.ProductFieldValues.Add(new ProductFieldValue(importantArgs, d["IMPORTANTARGUMENTS"].ToString()));
                product.addGroup(currentGroup);
                try
                {
                    product.Save();
                }
                catch (System.Data.SqlTypes.SqlTypeException ex)
                {
                    Base.w(ex.InnerException.ToString());
                    Base.w(ex.ToString());
                }
            }


Replies

 
Reply

The exception tells you, what's wrong. You're trying to insert an invalid date. Check the table for date fields and make sure they're filled correctly.

 

You must be logged in to post in the forum