Mój problem polega na tym, że nie mogę wydrukować wszystkich danych z tabeli w mojej bazie danych mysql, wydostałem właśnie ostatni wiersz w tabeli "nauczyciel". czy jest ktoś, kto może mi pomóc znaleźć błąd?Jak czytać i drukować dane z mysql w C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace ReadDataFromMysql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sql = " SELECT * FROM teacher ";
MySqlConnection con = new MySqlConnection("host=localhost;user=root;password=859694;database=projekt;");
MySqlCommand cmd = new MySqlCommand(sql, con);
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
data2txt.Text = reader.GetString("id");
datatxt.Text = reader.GetString("userId");
}
}
private void btnclose_Click(object sender, EventArgs e)
{
Close();
}
}
}
Mają cię umieścić punkt przerwania w pętli while? Twoje pola tekstowe zostaną wypełnione przez wszystkie wartości zwracane przez zapytanie i zostaną ustawione na ostatnią wartość, gdy pętla while powróci. – Liron