none
SubmitChanges will not submit anything... RRS feed

  • Question


  • //Here's my question, I do linq sql/object mapping...
    // Connecting to my database
    db = new DataContext(@"Data Source=C:\Esmeralda.sdf");
     
    // linking my DataGridView to my BindingSource
    mainDataGridView.DataSource = mainBindingSource;
     
    // SQL query using my object
    var customers = db.GetTable<Customer>();
    var q = from c in customers
    select c;
     
    // updating my BindingSource and so, my DataGridView...
    mainBindingSource.DataSource = q;
     
    //Now is my question, I create and fill rows in the DataGridView and then call this:
    db.SubmitChanges();
     
    But nothing gets inserted in the database.... What did i miss ?

    Thanks Smile

    Tuesday, June 3, 2008 3:56 PM

Answers



  • I got it almost sorted out.
    Actually the issue came from the object definition.
    in the database, I have a field called ID that's a bigint.
    In the object, the corresponding property was int.
    it mismatched.
    I replaced the int of the object by a long and it works out now.
    I still can't save updates made to the grid but I will close this thread and create a new one for that.

    Tuesday, June 3, 2008 7:21 PM

All replies

  • Can you confirm that SubmitChanges( ) behaves as expected without the DataGridView in the picture? (That is, are the changes persisted in the non-binding scenario?)

     

    See if you can narrow down the problem to the real source.

     

    Thanks.

     

    --Samir

     

     

    Tuesday, June 3, 2008 4:38 PM


  • They are:


                Customer c = new Customer();
                c.Name = "Pierre Act";
                c.Address = "Henrique Brostel";

                db.GetTable<Customer>().InsertOnSubmit(c);
                db.SubmitChanges();

    This code inserted the row in the database...
    Now, it must be a binding context issue, the problem might be very simple, it's the first time I use databinding.


    Tuesday, June 3, 2008 5:02 PM

  • Actually, the issue seem to come from this line:
    mainBindingSource.DataSource = q;

    Seems Like I have a casting problem but so far I couldn't resolve it.
    May you help me on this please?

    Sounds like what is returned by the select statement is of type IQueryable<Customer>
    and mainBindingSource.DataSource doesn't seem to accept it 
    So I tried to cast it explecitly like this:

                Table<Customer> customers = db.GetTable<Customer>();
                IQueryable<Customer> q = from c in customers
                                    select c;
                mainBindingSource.DataSource = (q as List<Customer>);

    But it didn't like it either...
    Help please
    Tuesday, June 3, 2008 5:34 PM

  • DataContext db = new DataContext(@"Data Source=C:\Esmeralda.sdf");
    Table<Customer> customers = db.GetTable<Customer>();
    mainBindingSource.DataSource = customers; // This gets an exception..
    // "Specified cast is not valid."
     
    //Any idea please ?
     
     
    System.InvalidCastException was unhandled
    Message="Specified cast is not valid."
    Source="System.Data.SqlServerCe"
    StackTrace:
    at System.Data.SqlServerCe.SqlCeDataReader.GetInt32(Int32 ordinal)
    at Read_Customer(ObjectMaterializer`1 )
    at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable`1 sequence)
    at System.Data.Linq.Table`1.GetNewBindingList()
    at System.Data.Linq.Table`1.System.ComponentModel.IListSource.GetList()
    at System.Windows.Forms.ListBindingHelper.GetList(Object list)
    at System.Windows.Forms.ListBindingHelper.GetList(Object dataSource, String dataMember)
    at System.Windows.Forms.BindingSource.ResetList()
    at System.Windows.Forms.BindingSource.set_DataSource(Object value)
    at Esmeralda.MainForm.clientesToolStripMenuItem_Click(Object sender, EventArgs e) in C:\from_disk\NekoConsulting\Esmeralda\Esmeralda\Esmeralda\MainForm.cs:line 59
    at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
    at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ToolStrip.WndProc(Message& m)
    at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at Esmeralda.Program.Main() in C:\from_disk\NekoConsulting\Esmeralda\Esmeralda\Esmeralda\Program.cs:line 18
    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

    Tuesday, June 3, 2008 7:08 PM


  • I got it almost sorted out.
    Actually the issue came from the object definition.
    in the database, I have a field called ID that's a bigint.
    In the object, the corresponding property was int.
    it mismatched.
    I replaced the int of the object by a long and it works out now.
    I still can't save updates made to the grid but I will close this thread and create a new one for that.

    Tuesday, June 3, 2008 7:21 PM
  • Hello

     

    How exactly do you call : db.SubmitChanges() ?

     


    btw. mainBindingSource.DataSource accepts IQueryable<Customer> it's the whole purpose in using the technique Smile

    Tuesday, June 3, 2008 11:06 PM


  • Well, it works now, not sure what was wrong...
    It started working a bit after I modified that property in the object...
    maybe some cached informations or so, I don't know.
    Thank for caring Smile
    Software progressing a lot since Smile
    Lovy C# / Dotnet.

    Tuesday, June 3, 2008 11:42 PM