.net - Working with MySQL in C# -
here's code print data terminal:
public static void writedata() { string connstring = "server=localhost;" + "database=db;" + "uid=user;" + "password=pass;"; mysqlconnection connection = new mysqlconnection(connstring); mysqlcommand command = connection.createcommand(); mysqldatareader reader; command.commandtext = "select * table1"; connection.open(); reader = command.executereader(); while (reader.read()) { (int = 0; < reader.fieldcount; i++) console.write(reader.getvalue(i).tostring() + " "); console.writeline(); } connection.close(); }
now i'd view results in datagridview
. tutorials i've found involve adding external data sources grid, have no idea how in mysql. (also please note have no experience in developing windows forms, guess gui development drag-and-drop anyway).
as daniel said, datatable sufficient this.
if use dataadapter can fill datatable , bind grid, e.g.:
datagridview.datasource = datatable
if set datagridview auto generate columns see each column in data table, else, need specify each column.
here code populate data table sql command:
using (sqldataadapter osqldataadapter = new sqldataadapter(osqlcommand)) { datatable odatatable = new datatable(); osqldataadapter.fill(odatatable); return odatatable; }
obviously use mysql classes instead of sql classes.
Comments
Post a Comment