Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Table Adapters


  • Please log in to reply
14 replies to this topic

#1 Josef1994

Josef1994

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 11:15 AM

Hi, I'm developing a program in c# and cannot find a way to refresh a table adapter of a main form from a different form. Does anyone know how to solve this kind a problem?
Thanks!

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 11:24 AM

What kind of table adapter are you talking about? Linq-to-SQL? Entity Framework? Your own custom bit?
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 11:32 AM

Sorry forgot to mention. Thanks for the reply!

A table adapter that is linked to an SQL Database.

#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 11:33 AM

Yes, a SQL database would be the point of a table adapter. But what kind of table adapter? (What library is providing the table adapter? There are several included with .NET so we need to know which one you're talking about)
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 11:44 AM

Not really sure what you're talking about. How can I find out?

#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 12:59 PM

Just tell us where you got the table adapter from.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#7 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 02:55 PM

After setting up a data source to a datagridview.

#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 03:00 PM

Sorry, but that's not entirely helpful either. The docs for that parameter say:

The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

  • The IList interface, including one-dimensional arrays.
  • The IListSource interface, such as the DataTable and DataSet classes.
  • The IBindingList interface, such as the BindingList(Of T) class.
  • The IBindingListView interface, such as the BindingSource class.


Each of these data sources have different semantics. What are you setting the data source to?

Billy3

Edited by Billy O'Neal, 29 March 2012 - 03:01 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#9 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 03:10 PM

Ok, I will explain to you how I;m populating the data grid view. On the top right of the grid view there is a small icon and I just clicked on it and set up a data source with a table from the SQL database and so on form load the gridview will just populate itself with the contents of the table from the database. So I have another form which I need to refresh the gridview of the other form after an update.

#10 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 03:20 PM

Hmm... it looks like you should be able to call DataGridView.ResetBindings on the DataGridView and the control will automatically repopulate itself.

Edited by Billy O'Neal, 29 March 2012 - 03:21 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#11 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 03:23 PM

No, I have two forms, and the datagridview is in the main form. And In a different form I want a button that when I click on it, the datagridview from the main form repopulates itself.

#12 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 03:26 PM

Ah, well pass a reference to the first form to the second form when you create the second form. Then expose some method on the first form which calls DataGridView.ResetBindings on the control in question on that form.

What language are you using (C# or VB.NET)? I'll whip up a quick example for ya...

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#13 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 29 March 2012 - 03:31 PM

C# mate, and thanks for the help!

#14 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:17 PM

Posted 29 March 2012 - 03:37 PM

This should get you the idea:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void ShowSecondForm()
    {
        // Pass a reference to the current form to the second form
        var form2 = new Form2(this);
        form2.Show();
    }

    public void UpdateDataGrid()
    {
        //Code that calls DataGridView.ResetBindings
    }
}

public partial class Form2 : Form
{
    /// <summary>
    /// A reference to the form with the datagrid we want to update.
    /// </summary>
    Form1 parentDataViewForm;

    // Note that we changed the constructor to require a "Form1"
    public Form2(Form1 dataViewForm)
    {
        parentDataViewForm = dataViewForm;
        InitializeComponent();
    }

    private void ForceDatagirdUpdateOnForm1()
    {
        parentDataViewForm.UpdateDataGrid();
    }
}

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#15 Josef1994

Josef1994
  • Topic Starter

  • Members
  • 111 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:17 PM

Posted 01 April 2012 - 07:44 AM

Thanks! Works Perfectly!

Though, I have found out that the program is skipping my breakpoints. It's saying that it can't hit breakpoints...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users