It's not showing the database in datagridview
I'm having trouble trying to show the database that the teacher gave me and the demo she gave me to based on
but it still now showing for some reason
1 Reply
using For_the_new_database.BLL.Friends_Services;
using For_the_new_database.DAL.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
the server is connected, I've to arranged the items so that in the upcoming test I have to do the same thing
idk what's wrong here
public partial class Friends_Form : Form
{
private Friend_Service_A A_Service;
private Friend_Service_B B_Service;
public Friends_Form()
{
A_Service = new Friend_Service_A();
B_Service = new Friend_Service_B();
InitializeComponent();
LoadData(); Load_Relationship();
}
private void LoadData()
{
if (A_Service == null || B_Service == null)
{
Console.WriteLine("A_Service or B_Service is null");
return;
}
var result = from f_0 in A_Service.Friend_getAll_A()
join f_1 in B_Service.Friend_getAll_B()
on f_0.IdMqh equals f_1.Id
select new
{
ID = f_0.Id,
Ten = f_0.Ten,
f_0.SoThich,
f_0.NgaySinh,
f_0.GioiTinh,
Ten1 = f_1.Ten,
};
dataGridView1.DataSource = result;
}
private void Load_Relationship()
{
var result1 = B_Service.Friend_getAll_B().ToList();
comboBox1.DataSource = result1;
comboBox1.ValueMember = "Id";
comboBox1.DisplayMember = "Ten";
}
public partial class Friends_Form : Form
{
private Friend_Service_A A_Service;
private Friend_Service_B B_Service;
public Friends_Form()
{
A_Service = new Friend_Service_A();
B_Service = new Friend_Service_B();
InitializeComponent();
LoadData(); Load_Relationship();
}
private void LoadData()
{
if (A_Service == null || B_Service == null)
{
Console.WriteLine("A_Service or B_Service is null");
return;
}
var result = from f_0 in A_Service.Friend_getAll_A()
join f_1 in B_Service.Friend_getAll_B()
on f_0.IdMqh equals f_1.Id
select new
{
ID = f_0.Id,
Ten = f_0.Ten,
f_0.SoThich,
f_0.NgaySinh,
f_0.GioiTinh,
Ten1 = f_1.Ten,
};
dataGridView1.DataSource = result;
}
private void Load_Relationship()
{
var result1 = B_Service.Friend_getAll_B().ToList();
comboBox1.DataSource = result1;
comboBox1.ValueMember = "Id";
comboBox1.DisplayMember = "Ten";
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int d = e.RowIndex;
textBox1.Text = dataGridView1.Rows[d].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[d].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[d].Cells[2].Value.ToString();
dateTimePicker1.Value = Convert.ToDateTime(dataGridView1.Rows[d].Cells[4].Value.ToString());
string gioiTinh = dataGridView1.Rows[d].Cells[3].Value.ToString();
if (gioiTinh.Equals(1))
{
checkBox1.Checked = true;
checkBox2.Checked = false;
}
else
{
checkBox1.Checked = false;
checkBox2.Checked = true;
}
comboBox1.Text = dataGridView1.Rows[d].Cells[4].Value.ToString();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int d = e.RowIndex;
textBox1.Text = dataGridView1.Rows[d].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[d].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[d].Cells[2].Value.ToString();
dateTimePicker1.Value = Convert.ToDateTime(dataGridView1.Rows[d].Cells[4].Value.ToString());
string gioiTinh = dataGridView1.Rows[d].Cells[3].Value.ToString();
if (gioiTinh.Equals(1))
{
checkBox1.Checked = true;
checkBox2.Checked = false;
}
else
{
checkBox1.Checked = false;
checkBox2.Checked = true;
}
comboBox1.Text = dataGridView1.Rows[d].Cells[4].Value.ToString();
}