Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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(); //zmienna stworzona do pokazania poniższym komunikacie informacji o zedytowaniu danego usera 

	                    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.
Posted
Updated 26-Aug-11 1:05am
v5
Comments
Herman<T>.Instance 26-Aug-11 6:19am    
first: no quotes for numeric fields!
so: textBox4.Text + "', FK_pokoj_id='" +
textBox5.Text + ", FK_zamowienie_id=" +
textBox6.Text + " WHERE
second: why don't you use onselectindexchanged event?

i tried something with my display and value member... i put on form 2 comboboxes for this fk's (change from textboxes) :

C#
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["dupa"]);            // nie musimy dawac w zapuyaniu as dupa wtedy bysmy Tuple napisali nazwA
            textBox6.Text = Convert.ToString(dr["FK_zamowienie_id"]);
            comboBox3.DataSource = zapytanie;
            comboBox3.DisplayMember = "dupa";
            comboBox3.ValueMember = "pokoj_id";
            comboBox3.SelectedIndex = -1;


mayby this way??

and then sometinh change in update query ??
 
Share this answer
 
ok that's no problem i can put there a numericUpDown.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900