ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
273
273
EMPFEHLEN
-
Hallo,
versuch mich grad an Datenbankverbindungen in C#, leider bekomm ich es nicht so
wirklich hin. Bücher und Quellen im Internet haben leider nicht weitergeholfen.
Hab ne UserForm und ein paar Felder drin, die ich mit ner Databinding befüllt hab.
Nun änder ich die Daten ab und die Änderungen sollen in die DB übernommen werden. Wie funktioniert das? Ich tu doch nicht ein Databinding zuweisen, damit ich später nochmal den UPDATE-Befehl aufbau oder sag welche Spalten mit welchen Werten befüllt werden müssen.
Wie mach ich das denn? (cmdSave_Click()
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
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 System.Data.SqlServerCe; namespace QManager { public partial class Client : Form { private DatabaseConnection oDatabaseConnection; private CurrencyManager oCurrencyManager; private SqlCeDataAdapter oDataAdapter; private DataSet oDataSet; private DataView oDataView; public Client() { new Client(-1); } public Client(int clientNumber) { InitializeComponent(); this.oDatabaseConnection = new DatabaseConnection(Properties.Settings.Default.qdataConnectionString + MainWindow.password); this.createDatabindings(clientNumber); this.loadClient(clientNumber); } private void Client_Load(object sender, EventArgs e) { } //private void Client_KeyPress(object sender, KeyPressEventArgs e) //{ // if(e.KeyChar==(char)27) // { // this.Close(); // } //} public void loadClient(int clientNumber) { } private void createDatabindings(int clientNumber) { String sSqlCommand = "SELECT * FROM Client"; if (clientNumber > -1) { sSqlCommand += " WHERE Client.Id = " + clientNumber; } SqlCeCommand sqlCommand; try { this.oDatabaseConnection.OpenConnection(); sqlCommand = new SqlCeCommand(sSqlCommand, this.oDatabaseConnection.getConnection()); sqlCommand.CommandType = CommandType.Text; oDataSet = new DataSet(); oDataAdapter = new SqlCeDataAdapter(sqlCommand); oDataAdapter.Fill(oDataSet); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(oDataAdapter); this.oDataView = new DataView(oDataSet.Tables[0]); oDataView.Table = oDataSet.Tables[0]; if (oDataSet.Tables[0].Rows.Count > 1) { this.cmdNext.Enabled = true; this.cmdPrevious.Enabled = true; } else { this.cmdNext.Enabled = true; this.cmdPrevious.Enabled = true; } this.oCurrencyManager = (CurrencyManager)this.BindingContext[oDataView]; this.lblClientNumber.DataBindings.Add("Text", oDataView, "Id"); this.chkActive.DataBindings.Add("Checked", oDataView, "Activ"); this.cboSalutation.DataBindings.Add("Text", oDataView, "Gender"); this.txtTitle.DataBindings.Add("Text", oDataView, "Title"); this.txtFirstName.DataBindings.Add("Text", oDataView, "FirstName"); this.txtLastName.DataBindings.Add("Text", oDataView, "LastName"); this.txtStreet.DataBindings.Add("Text", oDataView, "Street"); this.txtHouse.DataBindings.Add("Text", oDataView, "House"); this.txtZip.DataBindings.Add("Text", oDataView, "Zip"); this.txtCity.DataBindings.Add("Text", oDataView, "City"); this.txtPhone.DataBindings.Add("Text", oDataView, "Phone1"); this.txtPhone2.DataBindings.Add("Text", oDataView, "Phone2"); this.txtMobile.DataBindings.Add("Text", oDataView, "Mobile"); this.txtFax.DataBindings.Add("Text", oDataView, "Fax"); this.txtEMail.DataBindings.Add("Text", oDataView, "EMail1"); this.txtEMail2.DataBindings.Add("Text", oDataView, "EMail2"); this.txtBirthday.DataBindings.Add("Text", oDataView, "Birthday"); this.txtNotice.DataBindings.Add("Text", oDataView, "Notice"); this.cboEmployee1.DataBindings.Add("Text", oDataView, "Employee1"); this.cboEmployee2.DataBindings.Add("Text", oDataView, "Employee2"); this.txtAccountNumber.DataBindings.Add("Text", oDataView, "AccountNumber"); this.txtAccountOwner.DataBindings.Add("Text", oDataView, "AccountOwner"); this.txtAccountInstitutNumber.DataBindings.Add("Text", oDataView, "AccountInstituteNumber"); this.txtAccountInstitutName.DataBindings.Add("Text", oDataView, "AccountInstituteName"); //this.updateLblPosition(); oDataSet.Dispose(); oDataAdapter.Dispose(); sqlCommand.Dispose(); } catch (Exception ex) { MessageBox.Show("Exception: " + ex.Message); } finally { this.oDatabaseConnection.CloseConnection(); } } private void updateTitleInformation() { } private void cmdSave_Click(object sender, EventArgs e) { try { //was mach ich hier } catch (Exception ex) { MessageBox.Show("Exception: " + ex.Message); } finally { this.oDatabaseConnection.CloseConnection(); } } private void cmdPrevious_Click(object sender, EventArgs e) { if (oCurrencyManager.Position > 0) { oCurrencyManager.Position--; } this.updateTitleInformation(); } private void cmdNext_Click(object sender, EventArgs e) { if (oCurrencyManager.Position < oCurrencyManager.Count - 1) { oCurrencyManager.Position++; } this.updateTitleInformation(); } private void cmdAbort_Click(object sender, EventArgs e) { this.Close(); } } }
-
11.09.09 12:38 #2
- Registriert seit
- May 2007
- Ort
- Ostmanien
- Beiträge
- 33
Nicht? .. naja dann viel spass noch... wusste gar nicht das die .Net Entwickler künstliche Intelligenz implementiert hättenIch tu doch nicht ein Databinding zuweisen, damit ich später nochmal den UPDATE-Befehl aufbau oder sag welche Spalten mit welchen Werten befüllt werden müssen.
Ähnliche Themen
-
Update: update Spalte gleichzeitig als WHERE Bedingung
Von Steusi im Forum Relationale DatenbanksystemeAntworten: 10Letzter Beitrag: 30.06.09, 08:18 -
Update Trigger auch für ON DUPLICATE KEY UPDATE?
Von Herr_M im Forum Relationale DatenbanksystemeAntworten: 2Letzter Beitrag: 20.05.09, 08:16 -
Last Update
Von emexy im Forum PHPAntworten: 3Letzter Beitrag: 26.03.07, 15:48 -
UPDATE mit IF()
Von Sebigf im Forum Relationale DatenbanksystemeAntworten: 1Letzter Beitrag: 29.07.06, 18:14 -
PS Update 9.0.1
Von Lemming im Forum PhotoshopAntworten: 2Letzter Beitrag: 19.05.06, 13:49





Zitieren
Login





