良好的检索数据和更新的问题... [英] Problem with good retrieving data and update...

查看:48
本文介绍了良好的检索数据和更新的问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在真的需要您的帮助.我有一些代码.
就像您看到的那样,可以将一些值从表下载到列表框...:

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();
	}




现在我在listBox上获得了MouseUp的事件





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();
	        }




所以现在我已经将表格中的值下载到文本框中,如您所见..

现在,我可以在文本框中更改一些内容并更新为tbl_rezerwacja:




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=''" +


值是其他表中的ID :(FK_pokoj_id)是表tbl_haro中的FK(此表包含ID和名称)
其他(FK_zamowienie_id)是表tbl_daro中的FK(此表包含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




因此,我将所有值从tb_rezerwacja下载到文本框,最后2个为FK(例如FK_pokoj_id的值为2,FK_zamowienie_id的值为15.

我想查看表tbl_haro中的值名称和tbl_daro 名称 没有数字...

而下一个问题是,如果我在那里有名字,该如何更新呢?.

所以最好的方法是检索FK名称(在ID上)到组合框,设置此组合框在实际记录字段上的名称的值是关联的,并且也可以更改其他名称的可用值,然后进行更新 ...这是我要堆叠2周的问题

表格:




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




那是我的问题,我只是堆叠
真的需要您的帮助

此处的图像可能会帮助您:图像

PS如果不清楚,请随时提出.




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.

推荐答案

好的,我可以在其中放置一个numericUpDown.
ok that''s no problem i can put there a numericUpDown.


我尝试使用我的显示和值成员进行某些操作...为此fk设置了表格2组合框(从文本框更改):

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

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这样吗?

然后在更新查询中进行一些更改??



mayby this way??

and then sometinh change in update query ??


这篇关于良好的检索数据和更新的问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆