c# - How to populate gridview with mysql? -
i know how populate gridview asp:sqldatasource
have column of templatefield
in gridview
, when need modify sql alter grid content, lose templatefield
, think learn populate gridview
c#
can teach me or give me tutorial?
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using mysql.data.common; using mysql.data.mysqlclient; using system.data.sqlclient; using system.windows.forms; using system.data; public partial class viewadmin : system.web.ui.page { string myconstring = "server=localhost;" + "database=databasename;" + "uid=root;" + "password=;"; protected void page_load(object sender, eventargs e) { mysqlconnection conn = new mysqlconnection(myconstring); mysqlcommand cmd = new mysqlcommand("select * tablename;", conn); conn.open(); datatable datatable = new datatable(); mysqldataadapter da = new mysqldataadapter(cmd); da.fill(datatable); gridview.datasource = datatable; gridview.databind(); } }
Comments
Post a Comment