c# - DataGridView data retrieval confusion -
i'm trying retrieve data database after clicking view button windows form, every time click on view button same data in database copied in multiple rows in datagridview control, instead of retrieving same data starting in datagridview every time click on view button.
//for view button private void button2_click(object sender, eventargs e) { bindingsource bindingsource = new bindingsource(); bindingsource.datasource = businesslayer.view("select * itemmaster"); //passed business access layer class datagridview1.datasource = bindingsource; } //method in dataaccesslayer class public datatable view(string query) { //initialize connection object openconn(); //initalize command object passing string value command = new sqlcommand(query, connection); sqldataadapter da = new sqldataadapter(); da.selectcommand = command; //fill dataset table da.fill(dataset, thistable); return dataset.tables[thistable]; }
could please tell me how can solve problem
bindingsource bindingsource = new bindingsource(); datagridview1.items.clear(); bindingsource.datasource = businesslayer.view("select * itemmaster"); //passed business access layer class datagridview1.datasource = bindingsource;
try clearing gridview before binding datasource.
Comments
Post a Comment