tags:

views:

32

answers:

2

I'm playing around with the Northwind database and by reading some tutorials I see that Categories should have an Add method, but it ain't working. Something is missing and I would appreciate someone else who knows more for some feedback.

 public void AddCategory(string categoryname)
        {

 string connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString; 
                DataClasses1DataContext db = new DataClasses1DataContext(connstring);

 Category category = new Category();
              category.CategoryName = categoryname;
           //   db.Categories.Add(category); 
               db.SubmitChanges(); 
        }
+3  A: 

It should be

db.Categories.InsertOnSubmit(category);
Alexander Shirshov
Is that a change from previous, Scott Guthrie has clearly an add method, http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx.
marko
@marko: can you please re submit this link. returning Error
Asad Butt
A: 
        public void AddCategory(Category category)
        {
            NorthWindDataContext dataContext = new NorthWindDataContext();
            try
            { 
             dataContext.Categories.InsertOnSubmit(category);
             dataContext.SubmitChanges();
            }
            catch (Exception) { }
        } 
Asad Butt