none
LING to SQL insertion problem... RRS feed

  • Question

  • Hello, Using Visual studio 2010, added service based Database in VS 2010... When I run following code I have runs without an error but when I check my database after exiting application, row is not added in database...

    but I see it in my new record in datagridview...

    I tried following:

    1. Creating another database
    2. creating another application
    3. tried inserting with sqlconnection
    4. tried on another machine.
    dbDataContext db = new dbDataContext();

                    var newitem = new emp_detail
                    {


                        // newitem.user_id= txteid.Text.Trim(),
                        com_id = 1,//frm_com_sel.com_id ,
                        f_name = txtefname.Text.Trim(),
                        l_name = txtelname.Text.Trim(),
                        address = txteadd.Text.Trim(),
                        position = txteposition.Text.Trim(),
                        b_date = dtpebdate.Text.ToString(),
                        h_date = dtpehdate.Text.ToString(),
                        notes = txtenotes.Text.Trim(),
                        d_wages = txtedailywages.Text.Trim(),
                        h_phone = txtehphone.Text.Trim(),
                        mob_no = txtemobno.Text.Trim(),
                        bonus = txtebonus.Text.Trim(),
                        e_fname = txtecfname.Text.Trim(),
                        e_lname = txteclname.Text.Trim(),
                        e_relationship = txtecrelnshp.Text.Trim(),
                        e_phone = txtecphone.Text.Trim(),
                        e_mobno = txtecmobno.Text.Trim(),
                        ot_wages = txteotwages.Text.Trim()
                    };
                    db.emp_details.InsertOnSubmit(newitem);
                    db.SubmitChanges();
                    MessageBox.Show("Saved");

     

    Any help ??


    Ankithmt
    Sunday, September 25, 2011 6:13 PM

All replies

  • Hi Ankithmt,

    At first glance I cannot find any problem with your code.

    Are you sure there is no exception and the SubmitChanges runs properly?

     

     


    Regards, Peter

    //If a post answers your question, please click "Mark As Answer".
    //Also if a post seems to be helpful, please click "Mark as Helpful" on that post.
    Monday, September 26, 2011 11:58 AM
  • Hi,

    Has your table a Primary key defined?

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Monday, September 26, 2011 12:13 PM
  • Hi Ankithmt;

    This sounds like you are using a local database to the project and that the database you are checking after the program has completed is NOT the one that the program is using. Please read the following post to see if this is your issue.

    Debugging with Local Database File

     

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, September 26, 2011 7:47 PM
  • Submit run properly... and update is reflected in datagridview unless I restart visual studio 2010...
    Ankithmt
    Tuesday, September 27, 2011 5:27 AM
  • Yeah... Primary Key is auto Increment and com_id is foreign key...
    Ankithmt
    Tuesday, September 27, 2011 5:27 AM
  • I'll check it and reply as soon as possible...
    Ankithmt
    Tuesday, September 27, 2011 5:28 AM
  • I got this error after I change COPY TO OUTPUT DIRECTORY : COPY ALWAYS

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


    Ankithmt
    Tuesday, September 27, 2011 5:39 AM
  • Hi again,

    Please, check if your problem could be the same than described here:

    http://social.msdn.microsoft.com/Forums/hr/linqtosql/thread/1b0bff8b-43a9-42ac-9460-d2a28247d0cd

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Tuesday, September 27, 2011 7:58 AM
  • Hi,

     

    It sounds like a connection problem. Have you tried to connect to that DB with other tools like Management Studio or LinqPad?

    Just to check if it is working.


    Regards, Peter

    //If a post answers your question, please click "Mark As Answer".
    //Also if a post seems to be helpful, please click "Mark as Helpful" on that post.
    Tuesday, September 27, 2011 8:07 AM
  • I had this exact problem.  If you can put code into your program just for the purposes of checking the insert I believe you will find that the insert is done.  When you execute the next time (from VS) you will copy the database which does not have the new row and that is why you think it is not updating.  

    I think that the process you are using is so that you can have a "base" database for testing and with each test the database is copied from that "base" database.  

     


    Lloyd Sheen
    Tuesday, September 27, 2011 1:52 PM
  • I resolved it but keeping the database file outside the program folder but that way I can't make path of program dynamic...
    Ankithmt
    Wednesday, September 28, 2011 4:49 AM