Filling Form Data from Database
Our sample projects and report templates can help you learn the basics of working with our products.This example is outdated, you can check out the many other new examples in this category.This example shows how to fill form data from database.
using var connection = new MySqlConnection("Server=YOURSERVER;User ID=YOURUSERID;Password=YOURPASSWORD;Database=YOURDATABASE");
await connection.OpenAsync();
using var command = new MySqlCommand("SELECT mail, recipient FROM table;", connection);
using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
var mail = reader.GetString("mail");
var recipient = reader.GetString("recipient");
label.Text.Expression = $"Hello, {recipient}";
var pdf = pdfExporter.ExportForm(form);
var mailMessage = new MailMessage
{
From = new MailAddress("This email address is being protected from spambots. You need JavaScript enabled to view it. "),
Subject = "subject",
Body = "<h1>Hello</h1>",
IsBodyHtml = true,
};
mailMessage.To.Add(mail);
var attachment = new Attachment(new MemoryStream(pdf), MediaTypeNames.Application.Pdf);
mailMessage.Attachments.Add(attachment);
smtpClient.Send(mailMessage);
}