none
Cannot store data RRS feed

  • Question

  • I just changed workstations (old one died) and am now using VB express/SQL Express.  I am trying to create a small program to help me consolidate my files since I have been backing up the files and now have many duplicates.

    To aid in this I am attempting to create a little program to point out duplicates.

    To this end I create a new database and a new table.  The table has a primary key of an identity column.

    I attempted to put all the file info from my backup drive onto the database but to no avail.

    (no need to show this code yet)

    I then attempted to just input one row.

     

        Dim linqStuff As New DataClasses1DataContext
    
        Dim cnt1 As Integer = (From gg In linqStuff.GFiles Select gg).Count
        Dim stoper1 As Integer = 1
    
        Dim theNewRow1 As New GFile
        theNewRow1.FileDate = Now
        theNewRow1.FileName = "FileName"
        theNewRow1.FolderName = "FolderName"
    
        linqStuff.GFiles.InsertOnSubmit(theNewRow1)
    
        Dim cnt2 As Integer = (From gg In linqStuff.GFiles Select gg).Count
        Dim stoper2 As Integer = 1
    
    


    cnt1 is zero since there are no rows.

    There is no error when attempting to insert the row.

    cnt2 is also zero.  This is not correct.

    Help?


    Lloyd Sheen
    Wednesday, July 6, 2011 4:03 PM

Answers

  • I knew that.  The problem was that my project was copying the zero row database file on each execution.  The code sample was just there to prove that a row was being stored.

     

    Thanks


    Lloyd Sheen
    • Marked as answer by sqlguy Sunday, July 24, 2011 5:53 PM
    Saturday, July 9, 2011 2:11 PM
  • Thanks but the problem was that it was disabled.  I have now installed VS 2010 pro and all the problems associated with VB Express are gone.

     


    Lloyd Sheen
    Monday, July 11, 2011 2:02 PM

All replies

  • Call SubmitChanges() after your InsertOnSubmit.
    Wednesday, July 6, 2011 4:18 PM
  • Thanks, I missed that in my sample.  I have a SubmitChanges in the "real" code.

    Now I am really confused.  I put the SubmitChanges in and the count goes to 1.  Ok that is good.  I then go to the database explorer and attempt to look at the rows.  THERE ARE NONE!!!!

    I can create a row with the tools in VB express.  The row I create that ways stays and when I run again the first count is 1 and after the insert it is 2.  The problem is that after the program exits the data is not stored.

    Why oh why does MS have to make simple things complicated???

     


    Lloyd Sheen
    Wednesday, July 6, 2011 4:51 PM
  • One more really screwed up thing.  I go into the tools and remove the row.  When I execute again the row count is greater than zero.  I have no idea what is going on.  I have been programming databases for 40 years and this is the most perplexing thing I have seen.  Two tools that supposedly go against the same data giving different results.

     

     


    Lloyd Sheen
    Wednesday, July 6, 2011 4:53 PM
  • I figured first problem out.  It is copying a "template" of the database on each execution.

    Now I have a problem with IDENTITY_INSERT.  It is saying I cannot use an identity column for my primary key.  With the tools (or lack of same) for VB EXpress I can find no way to change this setting.

     

    HELP???

     


    Lloyd Sheen
    Wednesday, July 6, 2011 5:25 PM
  • Thank you for posting.

    When you are inserting a new object, after you call SubmitChanges method on it the value of the identity column will automatically be updated. So I think no need to explicitly fetch it. I suggest you can check this blog from Scott, you will get more helpful informaton from it. http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, July 9, 2011 12:33 PM
  • I knew that.  The problem was that my project was copying the zero row database file on each execution.  The code sample was just there to prove that a row was being stored.

     

    Thanks


    Lloyd Sheen
    • Marked as answer by sqlguy Sunday, July 24, 2011 5:53 PM
    Saturday, July 9, 2011 2:11 PM
  • Now I have a problem with IDENTITY_INSERT.  It is saying I cannot use an identity column for my primary key.  With the tools (or lack of same) for VB EXpress I can find no way to change this setting.

    Check this case. http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/23e5be4d-c1f1-49dd-aa9c-2431dcaa3c60/ 

    I don't know why you want to unable IDENTITY_INSERT. It looks you have a identity column, you just set its property to identity increasment and don't insert this column when you coded INSERT statement in your project.

    Thanks,

    Esters,


    Just a newbie for everything.
    Monday, July 11, 2011 10:36 AM
  • Thanks but the problem was that it was disabled.  I have now installed VS 2010 pro and all the problems associated with VB Express are gone.

     


    Lloyd Sheen
    Monday, July 11, 2011 2:02 PM