Click here to Skip to main content
Sign Up to vote bad
good
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:50
Edited 23 Feb '13 - 9:36
CHill6013.6K


1 solution

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 - 24 Feb '13 - 5:09
Thanks

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,286
1 OriginalGriff 6,561
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


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