|
-
Dec 17th, 2008, 03:41 PM
#1
Thread Starter
Lively Member
Data save twicw in the database
hi guys... i have a problem with my code...'
I dont get why using this code it save twice on the databse the intCategory item sace twice in the databse.
System.Data.SqlClient.SqlDataAdapter dacategs = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM tblICCategories", SqlConn);
System.Data.SqlClient.SqlCommandBuilder cbcategs = new System.Data.SqlClient.SqlCommandBuilder(dacategs);
System.Data.DataTable dtcategs = new System.Data.DataTable();
dacategs.Fill(dtcategs);
if (Item.Categories.Count > 0)
{
System.Data.SqlClient.SqlDataAdapter dacat = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM tblICInventoryCategory WHERE strProductID = '" + Item.Sku.Replace("'", "''") + "'", SqlConn);
System.Data.SqlClient.SqlCommandBuilder cbcat = new System.Data.SqlClient.SqlCommandBuilder(dacat);
System.Data.DataTable dtcat = new System.Data.DataTable();
dacat.Fill(dtcat);
dtcat.Clear();
dacat.Update(dtcat);
CommerceBuilder.Catalog.Category categ;
System.Data.DataRow rowcat;
foreach (int cat in Item.Categories)
{
categ = CommerceBuilder.Catalog.CategoryDataSource.Load(cat);
rowcat = dtcat.NewRow();
rowcat["strProductID"] = SizeDown(Item.Sku, 50);
rowcat["strGroup"] = "";
rowcat["intConcurrencyID"] = 0;
rowcat["intCategoryID"] = 0;
foreach (System.Data.DataRow rowc in dtcategs.Rows)
if (rowc["strCategory"].ToString().Equals(categ.Name))
{
rowcat["intCategoryID"] = rowc["intCategoryID"];
break;
}
dtcat.Rows.Add(rowcat);
}
dacat.Update(dtcat);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|