Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi All
 

my DGV database UPDATE Time This Error Show..
 
Unable to cast object of type 'System.Data.DataTable' to type 'System.Windows.Forms.BindingSource'.
 

Here I am USING CODE FOR UPDATE FUNCION
Me.Validate()
 Dim bindingSource1 As New BindingSource
 
        Dim DTable As New DataTable()
        Me.bindingSource1 = Me.dgvView.DataSource
        DTable = Me.bindingSource1.DataSource
        Me.DaAp.Update(DTable)
        MessageBox.Show("UPDATED SUCESSFULLY")
        DTable.AcceptChanges()
 

Please Tell Me How Can i Do to database UPDATE using DGV
Posted 23-Feb-13 8:50am
Edited 23-Feb-13 9:36am
CHill6060.7K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You REALLY need to go through a VB.NET book. This code is meaningless spaghetti.
 
You don't creat a new bindingsource to do a database update. On top of that, you're creating a new empty DataTable, then ignoring it and letting it go out of scope.
 
You normally have your data in a DataTable object, bind the Grid to it, and when the user wants to submit changes, you call the Update method of a DataAdapter configured to do the update. This is not a replacement for your code, but it comes down to this:
    MyDgv.EndEdit()
    MyDataAdapter.Update(myDataTable)
    MessageBox.Show("UPDATED SUCESSFULLY")
The rest of that code you posted is meaningless garbage.
  Permalink  
Comments
Navas Khanj at 24-Feb-13 5:09am
   
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 373
1 Sergey Alexandrovich Kryukov 197
2 Richard Deeming 160
3 PhilLenoir 120
4 RyanDev 115
0 Sergey Alexandrovich Kryukov 6,405
1 OriginalGriff 5,798
2 CPallini 2,473
3 Richard MacCutchan 1,647
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100