Refresh DataGridView when databound database table changes


i created datagridview , bound database table it:
        public virtual void gridadapt(string sel, datagridview dgv)
        {
            dbdataadapter da = getdataadapter(sel);
            dataset dsx = new dataset();
            da.fill(dsx);

            bindingsource bs = new bindingsource();
            bs.datasource = dsx.tables[0];
            dgv.datasource = bs;

            dbcommandbuilder cb = getcommandbuilder(da);
            da.insertcommand = cb.getinsertcommand();
            da.deletecommand = cb.getdeletecommand();
            da.updatecommand = cb.getupdatecommand();
        }
when edit columns in existing rows, changes propagated underlying database table, little forum (hooray!)
when move past last row, create default entry in underlying table. works fine.

what can't figure out how make new row appear in datagridview. guess need re-execute select statement somehow.

what need make new row show in grid?

thanks,


jon jacobs
in transmission, subatomic particles managed professionals.
no innocent electrons harmed.

hi jon,

if want refresh datagridview data, need bind again. recommend create method bind data datagridview, when need refresh, call again. code below:

private dbdataadapter da;

        public virtual void init(string sel)

        {

            dbdataadapter da = getdataadapter(sel);

            dataset dsx = new dataset();

            da.fill(dsx);

            dbcommandbuilder cb = getcommandbuilder(da);

            da.insertcommand = cb.getinsertcommand();

            da.deletecommand = cb.getdeletecommand();

            da.updatecommand = cb.getupdatecommand();

            bindingsource bs = new bindingsource();

            bs.datasource = dsx.tables[0];

            dgv.datasource = bs;

        }

        public void griddatabind(datagridview dgv)

        {

            dataset ds = new dataset();

            da.fill(ds);

            bindingsource bs = new bindingsource();

            bs.datasource = ds.tables[0];

            dgv.datasource = bs;

        }

you should modify above code suit app.

hope useful you.

best regards,


we trying better understand customer views on social support experience, participation in interview project appreciated if have time. helping make community forums great place.
click here participate survey.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'