Answer the question
In order to leave comments, you need to log in
How to write data to table from MySQL database?
How to display data from MySql database to a table?
here is what i get
Employee tabl = new Employee();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
fillGrid();
}
public void fillGrid() {
MysqlConn Conn = new MysqlConn();
MySqlDataReader reader = Conn.ConnectionDataBase(Con.RetSet("Host"), Con.RetSet("User"), Con.RetSet("DB"), Con.RetSet("Pass"), "SELECT * FROM s");
while (reader.Read())
{
tabl.EmployeeId = reader["id"].ToString();
tabl.EmployeePib = reader["pib"].ToString();
tabl.EmployeeEmail = reader["email"].ToString();
tabl.EmployeePhone = reader["phone"].ToString();
tabl.EmployeeMessage = reader["message"].ToString();
tabl.EmployeeIp = reader["ip"].ToString();
tabl.EmployeeDate = reader["send"].ToString();
tables.Items.Add(tabl);
}
// label1.Text = reader[3].ToString() + " " + reader[4].ToString();
//this.Text = label1.Text;
Conn.Cls();
}
public class Employee
{
public string EmployeePhone { get; set; }
public string EmployeeId { get; set; }
public string EmployeePib { get; set; }
public string EmployeeEmail { get; set; }
public string EmployeeMessage { get; set; }
public string EmployeeIp { get; set; }
public string EmployeeDate { get; set; }
}
<DataGrid x:Name="tables" Margin="0 8 0 0" ItemsSource="{Binding Items3}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False"
materialDesign:DataGridAssist.CellPadding="13 8 8 8" materialDesign:DataGridAssist.ColumnHeaderPadding="8">
<DataGrid.Columns>
<DataGridTextColumn Width="35" Binding="{Binding EmployeeId}"
Header="#"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
<!-- if you want to use the pop up style (MaterialDesignDataGridTextColumnPopupEditingStyle), you must use MaterialDataGridTextColumn -->
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeePib}"
Header="ПІБ"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
/>
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeeEmail}"
Header="E-mail"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeeMessage}"
Header="Message"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeePhone}"
Header="Телефон"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeeIp}"
Header="IP"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<materialDesign:MaterialDataGridTextColumn Width="*" Binding="{Binding EmployeeDate}"
Header="Дата"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
</DataGrid.Columns>
</DataGrid>
Answer the question
In order to leave comments, you need to log in
Probably something like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
tables.ItemsSource = fillGrid();
}
public class Employee
{
public string EmployeePhone { get; set; }
public string EmployeeId { get; set; }
public string EmployeePib { get; set; }
public string EmployeeEmail { get; set; }
public string EmployeeMessage { get; set; }
public string EmployeeIp { get; set; }
public string EmployeeDate { get; set; }
}
public List<Employee> fillGrid() {
MysqlConn Conn = new MysqlConn();
MySqlDataReader reader = Conn.ConnectionDataBase(Con.RetSet("Host"), Con.RetSet("User"), Con.RetSet("DB"), Con.RetSet("Pass"), "SELECT * FROM s");
var _list = new List<Employee>();
while (reader.Read())
{
var tabl = new Employee()
{
EmployeeId = reader["id"].ToString(),
EmployeePib = reader["pib"].ToString(),
EmployeeEmail = reader["email"].ToString(),
EmployeePhone = reader["phone"].ToString(),
EmployeeMessage = reader["message"].ToString(),
EmployeeIp = reader["ip"].ToString(),
EmployeeDate = reader["send"].ToString()
};
_list.Add(tabl);
}
Conn.Cls();
return _list;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question