I really need Your help now. I got some code.
like u see it's for download some value from table to listbox... :
private void OdczytajDaneDoListBoxEdytujKomputery()
{
listBox3.Items.Clear();
conn.Open();
string zapytanie = ("SELECT ilosc_osob FROM tb_rezerwacja");
MySqlCommand command = new MySqlCommand(zapytanie, conn);
command.ExecuteNonQuery();
MySqlDataReader dr = command.ExecuteReader(Commandbehavior.CloseConnection);
while (dr.Read())
{
string ilosc_osob = Convert.ToString(dr["ilosc_osob"]);
this.listBox3.Items.Add(ilosc_osob);
}
conn.Close();
}
Now i got event for MouseUp on listBox
private void listBox3_MouseUp(object sender, MouseEventArgs e)
{
EdycjaKomputerowPobranieDanychDoTextBoxow();
}
private void EdycjaKomputerowPobranieDanychDoTextBoxow()
{
ilosc_osob = listBox3.Items[listBox3.SelectedIndex].ToString();
conn.Open();
string zapytanie = ("SELECT * FROM tb_rezerwacja WHERE ilosc_osob='" + ilosc_osob + "';");
MySqlCommand command = new MySqlCommand(zapytanie, conn);
command.ExecuteNonQuery();
MySqlDataReader dr = command.ExecuteReader(Commandbehavior.CloseConnection);
dr.Read();
textBox1.Text = Convert.ToString(dr["ilosc_osob"]);
textBox2.Text = Convert.ToString(dr["w_tym_ilosc_dzieci"]);
textBox3.Text = "data_od";
textBox4.Text = "data_do";
textBox5.Text = Convert.ToString(dr["FK_pokoj_id"]);
textBox6.Text = Convert.ToString(dr["FK_zamowienie_id"]);
conn.Close();
}
So now I've been download a values from table to textboxes like u see..
Now i can change some in textboxes and make update to tbl_rezerwacja:
private void button6_Click(object sender, EventArgs e)
{
DialogResult wybor = MessageBox.Show("Czy jesteś pewien tego kroku?", "Dodawanie nowego komputera", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (wybor == DialogResult.OK)
{
if ((this.textBox1.Text.Length != 0) && (this.textBox2.Text.Length != 0))
{
string zapytanie = ("UPDATE tb_rezerwacja SET ilosc_osob='" +
textBox1.Text + "', w_tym_ilosc_dzieci='" +
textBox2.Text + "', data_od='" +
textBox3.Text + "', data_do='" +
textBox4.Text + "', FK_pokoj_id='" +
textBox5.Text + "', FK_zamowienie_id='" +
textBox6.Text + "' WHERE ilosc_osob='" + ilosc_osob + "';");
conn.Open();
MySqlCommand command = new MySqlCommand(zapytanie, conn);
command.ExecuteNonQuery();
conn.Close();
OdczytajDaneDoListBoxEdytujKomputery();
Pobierz_spis_komputerow();
string user = textBox1.Text.ToString();
MessageBox.Show("Proces aktualizacji wykonano pomyślnie dla: " + user);
}
else
{
}
}
}
SO WHAT'S MY PROBLEM?
in this line's:
textBox4.Text + "', FK_pokoj_id='" +
textBox5.Text + "', FK_zamowienie_id='" +
this
values are id's from other tables: (FK_pokoj_id) is FK from table tbl_haro (this table contains an id and name)
other (FK_zamowienie_id) is FK from table tbl_daro (this table contains an id and name)
Information:
this 3 tables are 1:1
tbl_rezerwacja 1:1 tbl_haro
tbl_rezerwacja 1:1 tbl_daro
So i download all values from tb_rezerwacja to textboxes last 2 are FK (for example value 2 for FK_pokoj_id and value 15 for FK_zamowienie_id.
I WANT TO SEE THERE
a value name from table tbl_haro and
name for tbl_daro
no numbers...
and the next problem is how to update it if i will have names there..?
So the best way will retrive FK names (on id's) to comboboxes set values this comboboxes on name on actually record fields is relation on and rest too for available change for some other name and then update... that's problem i am stack 2 weeks
tables:
tbl_haro tbl_daro tb_rezerwacja
--------- --------- -----------
pokoj_id zamowienie_id rezerwacja_id
name name ilosc_osob
w_tym_ilosc_dzieci
data_od
data_do
FK_pokoj_id
FK_zamowienie_id
That's my problem i am just stack
and really need Your help
here's image mayby help:
IMAGE
P.S If some not clear feel free to ask.