Пример кода C# работа с базой данных
← разместить еще кодРасшаренный код:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using FirebirdSql.Data.FirebirdClient; namespace HOTEL { public partial class Client : Form { public Client() { InitializeComponent(); } private void pERSONBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.pERSONBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.dataSet1); } private void Client_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dataSet1.PERSON' table. You can move, or remove it, as needed. this.pERSONTableAdapter.Fill(this.dataSet1.PERSON); // TODO: This line of code loads data into the 'dataSet1.PERSON' table. You can move, or remove it, as needed. this.pERSONTableAdapter.Fill(this.dataSet1.PERSON); // TODO: This line of code loads data into the 'dataSet1.PERSON' table. You can move, or remove it, as needed. // this.pERSONTableAdapter.Fill(this.dataSet1.PERSON); } private void pERSONBindingNavigatorSaveItem_Click_1(object sender, EventArgs e) { this.Validate(); this.pERSONBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.dataSet1); } private void button1_Click(object sender, EventArgs e) { NewClient nc = new NewClient(); nc.Show(); } private void pERSONBindingNavigatorSaveItem_Click_2(object sender, EventArgs e) { this.Validate(); this.pERSONBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.dataSet1); } private void pERSONDataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { NewReserv nr = (NewReserv)this.Owner; if (pERSONDataGridView.CurrentCell != null && pERSONDataGridView.CurrentCell.Value != null) { nr.textBox1.Text = pERSONDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString(); nr.id_client = Convert.ToInt32(pERSONDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()); Close(); } } catch(System.InvalidCastException) { } try { Occupation nr = (Occupation)this.Owner; if (pERSONDataGridView.CurrentCell != null && pERSONDataGridView.CurrentCell.Value != null) { nr.textBox1.Text = pERSONDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString(); nr.id_client = Convert.ToInt32(pERSONDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString()); Close(); } } catch (System.InvalidCastException) { } try { Client_Service cs = (Client_Service)this.Owner; if (pERSONDataGridView.CurrentCell != null && pERSONDataGridView.CurrentCell.Value != null) { cs.textBox1.Text = pERSONDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); Close(); } } catch (System.InvalidCastException) { } try { ReportClient cs = (ReportClient)this.Owner; if (pERSONDataGridView.CurrentCell != null && pERSONDataGridView.CurrentCell.Value != null) { cs.textBox1.Text = pERSONDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); Close(); } } catch (System.InvalidCastException) { } } private void textBox1_TextChanged(object sender, EventArgs e) { if (pERSONDataGridView.DataSource == pERSONBindingSource) { pERSONBindingSource.Filter = "[surname]LIKE'" + textBox1.Text + "%'"; } } private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (pERSONDataGridView.RowCount <= 0) return; DataRow del = ((DataRowView)pERSONBindingSource.Current).Row; string message = "Вы действительно хотите удалить клиента?"; string caption = "Удаление"; MessageBoxButtons buttons = MessageBoxButtons.OKCancel; MessageBoxIcon icon = MessageBoxIcon.Question; // Show message box DialogResult result = MessageBox.Show(message, caption, buttons, icon); if (result == DialogResult.OK) { FbCommandBuilder fbCommandBuilder = new FbCommandBuilder(pERSONTableAdapter.Adapter); del.Delete(); pERSONBindingSource.EndEdit(); pERSONTableAdapter.Adapter.Update(dataSet1, "PERSON"); } } private void добавитьИностранцаToolStripMenuItem_Click(object sender, EventArgs e) { Foreigner f = new Foreigner(); f.ShowDialog(); } private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) { } } }