Mysql connection class (beginner)
i new c#, have learned how connect database using code.
now, have form contain richtextbox1, display text in database follow. not sure missing.
public class mysqlconnect{
public string connstring;
public mysqlconnect()
{
connstring = "server=127.0.0.1;port=3306;database=shawn_db;uid=root;password=";
mysqlconnection conn = new mysqlconnection(connstring);
try
{
conn.open();
messagebox.show("connected!!!");
}
catch (exception ex)
{
messagebox.show(ex.message);
}
}
}
public form1()
{
initializecomponent();
mysqlconnect connstring = new mysqlconnect();
mysqlcommand command = connstring.createcommand();
command.commandtext = "select * shawn_jr_list order id desc limit 0, 1";
mysqldatareader reader = command.executereader();
while (reader.read())
{
richtextbox1.text = reader[4].tostring();
}
}
in output can see alert box saying "connected!!" couldn't see text of database in richtextbox1.
help please.
put break point in while loop, , see if reader has value.
if not, check query.
if yes, check that reader[4] has value.
noam b.
not forget vote answer/helpful, please. encourages you...
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment