locked
not saving data in dB using LINQ - not showning any errors. RRS feed

  • Question

  • User-1738998028 posted

    Hi,

    I have below code

    fts.Models.FileShare fShare = new fts.Models.FileShare();
                            fShare.FileShareId = fileShareId;
                            fShare.GenerateName = generateName;
                            fShare.CreatedDate = System.DateTime.Now;
                            fShare.ModifiedDate = System.DateTime.Now;

                            db.FileShares.Add(fShare);

                            try
                            {
                                db.SaveChanges();
                            }
                            catch(Exception exx)
                            {
                                Span1.Text += "Error: <br>" + exx.Message;
                            }

    Everything pass and not having any error, but not saving in db.

    some coder are below

     public class FTPContext : DbContext
        {
            public FTPContext() : base("ERP")
            {
            }
            public DbSet<FileShare> FileShares { get; set; }

            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
            }

        }

    Please kindly advice

    Monday, April 20, 2015 12:33 PM

Answers

  • User753101303 posted

    Hi,

    What is the return value for SaveChanges? (it returns the number of altered objects) Sometimes the issue is not checking the right database file or that the db is later updated again (recreated, overwritten or whatever) so the code does work fine and still the expected row is not found in the db file you are checking.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2015 12:42 PM
  • User-1738998028 posted

    Hi,

    That was my mistake, program was working perfectly. code create table name called FileShares.

    So I can check in that table, everything saved and working

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2015 3:22 AM

All replies

  • User753101303 posted

    Hi,

    What is the return value for SaveChanges? (it returns the number of altered objects) Sometimes the issue is not checking the right database file or that the db is later updated again (recreated, overwritten or whatever) so the code does work fine and still the expected row is not found in the db file you are checking.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2015 12:42 PM
  • User-1738998028 posted

    Hi,

    That was my mistake, program was working perfectly. code create table name called FileShares.

    So I can check in that table, everything saved and working

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2015 3:22 AM