FarPoint + Linq +Single Record Insertion Problem

Posted by: newtofarpoint on 8 September 2017, 1:30 pm EST

  • Posted 8 September 2017, 1:30 pm EST

    Hi,


     I have been using Visual Studio 2005 and LINQ with Spread for Windows Forms 4 and i find that i am unable to insert a single record whereas i can insert multiple records.


    Has anybody else faced this problem ??

  • Replied 8 September 2017, 1:30 pm EST

    Hello,


    How are you trying to add the record into Spread?

  • Replied 8 September 2017, 1:30 pm EST

    I am not trying to insert a record in Spread.


    I am trying to insert the data into the database.


    If i enter more than one row of data and click Save (in the backend using LINQ command DataContext.SubmitChanges()) , it works fine


    but i try to save just one record it does not give me any error but it does not insert the one row of data.


    Any ideas ??

  • Replied 8 September 2017, 1:30 pm EST

    Hello,


    You would need to click off the row onto another row of Spread before trying to save the record. Or you can get the bound DataSource from the Spread and call the EndEdit method on the bound DataRow that is being changed.

  • Replied 8 September 2017, 1:30 pm EST

    Hi,


    I have set the DataAllowAddNew property to true to allow the user to add new rows in addition to the existing bound rows.


    Clicking on a new row is just going to give me a Null Exception. 


     

  • Replied 8 September 2017, 1:30 pm EST

    Hello,


    What line of code are you getting a NullReference exception? Are you filling the data into the new row before clicking on a new row? Could you post a small zipped project reproducing this issue for us to debug?

  • Replied 8 September 2017, 1:30 pm EST

    Hi,


    I am sorry about the part that i told you that it gives me a null reference exception and also for the late response


    But the main problem is while using LINQ it gives us the flexibilty to Commit the changes directly from the grid.


    But when the user enters data in a single row and Clicks Save the data is not inserted in the database.


    But if the user enters more than one row of data and Clicks Save the data is inserted into the table.


     


    Can you explain by what you mean


    Get the bound DataSource from the Spread and call the EndEdit method on the bound DataRow that is being changed.

  • Replied 8 September 2017, 1:30 pm EST

    Hello,


    With LINQ, the EndEdit method I was talking about is not necessary. This is used when binding to DataSet/DataTables. I created a Linq to SQL class and bound the Spread to this object and was able to make a changte to one row and update the database with this change. Here is my code for setting the DataSource of my BindingSource to the Linq to Sql class and then updating the change when clicking the button. The Spread is bound to the Binding Source. Could you let me know how you are doing this differently for us to debug the issue you are seeing?


    Private test As NwndDataContext


    Public Sub New()


    ' This call is required by the Windows Form Designer.


    InitializeComponent()


    ' Add any initialization after the InitializeComponent() call.


    test = New NwndDataContext


    CustomerBindingSource.DataSource = test.Customers


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    test.SubmitChanges()


    End Sub

  • Replied 8 September 2017, 1:30 pm EST

    Hi,


    I have though solved this problem for the moment.


    I have done the same asa you have shown me.


    the only difference was that i had a spread in which i had designed the columns.


    So i had to databind the columns individually.


    I would like to add for other people here who are using LINQ or are going to use LINQ as long as you are including all the columns from the table that you are


    inserting data there is no problem.But if you don't include all the columns from the table(things which can be null or are populated from other tables) and try to insert the data then it is going to give the users a problem


     


     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels