Answer the question
In order to leave comments, you need to log in
How to store and display records with text from a database with formatting support?
The form has the following objects: richTextBox, 2 Button and ListBox.
an entry is selected in the Listbox.
private void MyListBox_SelectedIndexChanged(object sender, EventArgs e)
{
Patient_id = Convert.ToInt32(MyListBox.SelectedIndex);
MySqlConnection con = new MySqlConnection(AppSetting.ConnectonString());
MySqlCommand cmd;
cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM patients WHERE id='" + MyListBox.SelectedValue + "';";
try
{
con.Open();
MySqlDataReader sdr = cmd.ExecuteReader();
// Загружаем данные
while (sdr.Read())
{
string sNaz = sdr.GetString("Naz");
richTextBox1.Text = sNaz;
}
con.Close();
}
catch (Exception)
{
MessageBox.Show("Подключение к серверу отсутствует");
}
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold ^ richTextBox1.SelectionFont.Style);
richTextBox1.Select();
}
private void button2_Click(object sender, EventArgs e)
{
if (Patient_id != -1) // Если выбран пациент из списка
{
MySqlConnection con = new MySqlConnection(AppSetting.ConnectonString());
con.Open();
MySqlCommand cmd;
cmd = con.CreateCommand();
cmd.CommandText = "UPDATE patients set [email protected] WHERE id='" + MyListBox.SelectedValue + "';";
cmd.Parameters.AddWithValue("@Naz", richTextBox1.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Пациент обновлен", "Сообщение");
}
else
{
MessageBox.Show("Выберите пациента", "Сообщение");
}
}
Answer the question
In order to leave comments, you need to log in
RichTextBox1.Rtf stores text with all formatting . Save and load it to save formatting
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question