Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:44:04+00:00 2026-06-08T17:44:04+00:00

I have a VB.NET 2010 application that loads data from SQL Server to a

  • 0

I have a VB.NET 2010 application that loads data from SQL Server to a datagridview through adapter.fill(). When I update the database it works fine but my problem is that when i use the dataview to filter the data based on combobox selection the method adapter.update(table) does not work!

Is there away to do it with the filter applied?

Private Sub cmbDepartment_SelectedIndexChanged(...) 
        Handles cmbDepartment.SelectedIndexChanged 
    Dim filter As String 
    Try 
        lblDepartmentId.Text =   ds.Tables("department").Rows(cmbDepartment.SelectedIndex)(0) 
        filter = "dprtId = " & lblDepartmentId.Text 
        dvSection = New DataView(ds.Tables("section"), filter, "", DataViewRowState.CurrentRows) 
        table = dvSection.ToTable 
        dgvSections.DataSource = table 
    Catch ex As Exception 
        MsgBox(Err.Description) 
    End Try 
 End Sub

Private Sub btnSaveDepartment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        Handles btnSaveDepartment.Click 
    Dim cbDep As SqlCommandBuilder 
    Dim numRows As Integer 
    Try cbDep = New SqlCommandBuilder(daDep) 
        Me.Validate() numRows = daDep.Update(ds.Tables("section")) 
        MsgBox(numRows & " Rows affected.") 
    Catch ex As Exception 
        MsgBox(Err.Description) 
    End Try 
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:44:07+00:00Added an answer on June 8, 2026 at 5:44 pm

    The way you are currently doing your filtering is by creating a new DataTable and binding this to your DataGridView data source. This breaks the association between the original DataSet and that table so when you call Update your changes are not recovered.

    Try changing to something like the code below instead (I’ve left out the try catch blocks, they don’t change the idea that fixes your problem).

    When you first set the data source to the grid set it to a form level private dvSection field:

    Public Class Form1
    
        ' Here we declare some class level variables. 
        'These are visible to all members of the class
    
        Dim dvSection As DataView
        Dim tableAdapter As New DataSet1TableAdapters.CustomersTableAdapter()
        Dim ds As New DataSet1()
    
    
        Public Sub New()
    
            ' This call is required by the designer.
            InitializeComponent()
    
           ' We fill our dataset - in this case using a table adapter
            tableAdapter.Fill(ds.Customers)
            dvSection = ds.Customers.DefaultView
    
            DataGridView1.DataSource = dvSection
    
        End Sub
    
        ' Here is the code to filter.
        ' Note how I refer to the class level variable dvSection
        Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    
            Dim filter As String 
    
            lblDepartmentId.Text =   ds.Tables("department").Rows(cmbDepartment.SelectedIndex)(0) 
    
            filter = "dprtId = " & lblDepartmentId.Text 
            dvSection.RowFilter = filter 
    
            dvSection.RowFilter = filter
    
        End Sub
    
        ' And here is the update code referring to the class level table adapter
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            tableAdapter.Update(ds.Customers)
        End Sub
    End Class
    

    One other approach that might make things easier is to introduce a binding source and set the filter on that. Either was should work fine however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Visual Studio 2010 ASP.NET Web Application. I've noticed that if
I have a vb.net 2010 form with 22 data bound controls from two tables
I have an asp.net application that i am modifying. I setup visual studio 2010
I have an asp.net web application (c#) in visual studio 2010 that is heavily
So I have a .net web application that I use the VS 2010 publish
We have a ASP.Net web application running in Visual Studio 2010 that is targeting
I have created a Visual Studio 2010 ASP.NET Web Application. With it I have
I have developed a WinForm Application with VB.Net (VS2010) having Office 2010 Professional Installed,
Background - Visual Studio 2010, C#, .Net Framework 4.0 application I have a web
I have a .NET project in VS 2010 that has grown to consist of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.