CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Update Datagridview automatically

    Hi everybody,

    I'm using Visual Studio 2008 and trying to develop an SQL application interface.

    SQL Server 2005 Express Management Studio is installed on my Pc and I'm using it to create or edit databases.

    I've added a Datagridview object on my form and successfully created the SQL Database connection. I can read and write data from my Database. And also I can show data in Datagridview.

    But it's getting complicated when I'm trying to use SqlDependency object (which is informing me when database updated by someone else).

    I'm trying to uptade Datagridview when database updated by another person who I can't reach or control. So I've created an SqlDependency OnChange eventhandler, and write down some codes (you can see the code block below) into this eventhandler's function.

    void databaseUpdated(object sender, SqlNotificationEventArgs e)
    {
    sqlComm.Parameters.Clear();
    sqlDataAdap = new SqlDataAdapter(sqlComm);
    sqlDataAdap.Fill(sqlDs)
    dataGridView1.DataSource = sqlDs.Tables[0];
    MessageBox.Show("Updated! Check database!");
    }

    This function is not work!.. And throw this error
    "The query notification subscription message is invalid "

  2. #2
    Join Date
    Dec 2009
    Posts
    109

    Re: Update Datagridview automatically

    If you're just trying to refresh the Datagridview, clear out the Dataset that you are using to populate the Datagridview.

    Try clearing out the dataset using,
    sqlDs.tables[0].rows.clear();

    And then fill data into it again. See if this works.

    Basically what I mean is, replace
    Code:
    sqlComm.Parameters.Clear();
    with the line that I gave you.

    By the way, if you wanna show code, put it within 'code' tags. It's more easier to understand that way.

    Also, where exactly have you specified the parameters?
    Last edited by Dragster93; November 4th, 2011 at 09:54 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured