c# - Populate a datagridview with sql query results -
i'm trying present query results, keep getting blank data grid. it's data not visible
here code:
private void employee_report_load(object sender, eventargs e) { string select = "select * tblemployee"; connection c = new connection(); sqldataadapter dataadapter = new sqldataadapter(select, c.con); //c.con connection string sqlcommandbuilder commandbuilder = new sqlcommandbuilder(dataadapter); datatable table = new datatable(); table.locale = system.globalization.cultureinfo.invariantculture; dataadapter.fill(table); bindingsource1.datasource = table; datagridview1.readonly = true; datagridview1.datasource = bindingsource1; }
what's wrong code?
here's code fixed up. next forget bindingsource
var select = "select * tblemployee"; var c = new sqlconnection(yourconnectionstring); // connection string here var dataadapter = new sqldataadapter(select, c); var commandbuilder = new sqlcommandbuilder(dataadapter); var ds = new dataset(); dataadapter.fill(ds); datagridview1.readonly = true; datagridview1.datasource = ds.tables[0];
Comments
Post a Comment