Show entire table from mysql in C# (WPF) -



Show entire table from mysql in C# (WPF) -

i'm trying long time, can not it.

i have simple xaml:

<window ....> <grid> <button x:name="tlacitko" content="button" horizontalalignment="left" height="38" margin="343,259,0,0" verticalalignment="top" width="149" click="button_click"/> <textblock x:name="vypisblock" horizontalalignment="left" height="188" margin="32,25,0,0" textwrapping="wrap" text="" verticalalignment="top" width="442"/> </grid> </window>

and .cs

.. usings .. namespace pokus { public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void button_click(object sender, routedeventargs e) { string cs = @"server=localhost;userid=root; password=vertrigo;database=vzkaznik"; mysqlconnection conn = null; mysqldatareader rdr = null; seek { conn = new mysqlconnection(cs); conn.open(); string stm = "select * elsvo_zpravy"; mysqlcommand cmd = new mysqlcommand(stm, conn); rdr = cmd.executereader(); while (rdr.read()) { string vypis = ""; vypis += (rdr.getint32(0) + " - " + rdr.getstring(1) + " - " + rdr.getstring(2) + " - " + rdr.getstring(3) + "\n"); vypisblock.text = vypis; } } grab (mysqlexception ex) { string chyba = "error: {0}" + ex.tostring(); // doplnit (if = cislo chyby -> hlaska) místo šílenosti co zobrazuje ted vypisblock.text = chyba; } } } }

i want application indicated contents of entire table shows lastly line.

how do that?

thank

you overwrite result in while loop.

stringbuilder vypis = ""; while (rdr.read()) { vypis.appendline(string.format("{0} - {1} - {2} - {3}", rdr.getint32(0), rdr.getstring(1), rdr.getstring(2), rdr.getstring(3)); } vypisblock.text = vypis.tostring();

c# mysql wpf database visual-studio

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -