none
Binding Linq Table to Datagridview RRS feed

  • Question

  • Hello,

    I'm attempting to query a SQL database using Linq to SQL, attach the query results to a BindingSource, and set a DataGridView's Data Source to the BindingSource.

    The records are retrieved without any issue, but I want changes to the DataGridView to be immediately posted to the database. The changes show up in the BindingSource when I insert a breakpoint, but DataContext.SubmitChanges() doesn't seem to actually do anything since the changes are gone upon reload.

    Here's some of my code -- any suggestions?


    Code Snippet
    public Create_Order()
    {
    InitializeComponent();

    dc = new CascadeDataContext("Server=.\\; Database=CascadeSQL;Trusted_Connection=Yes;");

    var myQuery = from a in dc.View_Availabilities select a;

    myBindingSource.DataSource = myQuery;

    dgvAvailability.DataSource = myBindingSource;
    dgvAvailability.AutoGenerateColumns = true;
    }

    private void dgvAvailability_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
    myBindingSource.EndEdit();

    dc.SubmitChanges();

    }


    Thanks,
    -Brandon

    Thursday, July 3, 2008 1:50 AM

All replies

  • Is this in the right location, or should I move it to a DataBinding or Windows Forms forum?

    Thanks,
    -Brandon
    Thursday, July 3, 2008 11:51 PM
  • You should be able to submit the changes to database if the object returned is persistable to database. What kind of result does your query return? Is the entitytype bound to a database object?

    Thursday, July 24, 2008 4:45 AM