Я загрузил образец datagridview и сохраненные данные из базы данных.< /p>
Код: Выделить всё
private void button3_Click(object sender, EventArgs e)
{
if (productionid1.Text == "")
{
MessageBox.Show("Enter the Production id");
}
string query1 = "Select property_used.Production_Id, property_used.Location_Id, property_used.Property_Id, location.Location_Name from property_used inner join location on property_used.Location_Id = location.Location_Id where property_used.Production_Id = @PI";
MySqlCommand cmd1 = new MySqlCommand(query1, con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd1.Parameters.Add("@PI", MySqlDbType.Int32).Value = productionid1.Text;
MySqlDataReader reader2;
reader2 = cmd1.ExecuteReader();
if (reader2.Read())
{
locationid.Text = reader2[1].ToString();
locationname.Text = reader2[3].ToString();
}
reader2.Close();
con.Close();
}
}
#code for datagridview data
public void news()
{
ds = new DataSet();
ds.Tables.Add(GetDataTable());
ds.Tables[0].Columns.Add("Select_Property", typeof(bool));
DataTable dt = ds.Tables[0];
dataGridView1.DataSource = dt;
}
private DataTable GetDataTable()
{
var dt = new DataTable();
using (var CON = new MySqlConnection("connectionstring"))
using (var cmd = new MySqlCommand("Select Property_Name, Property_Id from property", CON))
using (var da = new MySqlDataAdapter(cmd))
{
CON.Open();
da.Fill(dt);
}
return dt;
}


Подробнее здесь: https://stackoverflow.com/questions/790 ... -available