Autor Beitrag
Skywalker19
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Di 10.01.06 12:21 
Ich möchte in C# Inhalte aus Tabellen in Datagrids in einer Oracle DB speichern. Die Verbindung zur DB hab ich schon hergestellt. meine Tabellen hab ich in Datasets gepackt. Wie kann ich nun meine Tabelleninhalte in die DB abspeichern? Hab in C# bis jetzt noch nix mit Datenbanken zu tungehabt.
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Sa 28.01.06 15:35 
So habe ich das in einem Beispiel auf einer anderen Seite gefunden. Hier wird allerdings MS Access verwendet. Vielleicht hilft es Dir ja.

ausblenden volle Höhe C#-Quelltext
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:
private void fnSaveNewRecord() 
{
  try
  {
     string strInsert;
     strInsert = "insert into PersonTable" + 
        "(FirstName, LastName, Title, City,Country)" 
        + " values('" + this.textboxFirstname.Text + "', '"
        + this.textboxLastname.Text + "', '"
        + this.textboxTitle.Text + "', '"
        + this.textboxCity.Text + "', '"
        + this.textboxCountry.Text + "')";
     if (this.textboxFirstname.Text !="" && 
           this.textboxLastname.Text !=""&& 
           this.textboxTitle.Text !="" && 
           this.textboxCity.Text !="" 
           && this.textboxCountry.Text !=""
     { 
         this.oleDbDataAdapter1.InsertCommand.CommandText = strInsert;
         //do the insert
         this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
         //Get the last PersonID from the table and display it in TextBox
         fnGetLastPersonID(); 
         fnEnableButtonsNextPreviousLastFirst(true);
         fnEnableToolbarButtons(true"Edit"); 
         fnEnableToolbarButtons(true"Delete"); 
         fnEnableToolbarButtons(false"Save");
         this.fnEnableDisableTextBox(false); 
     }else 
     {
         MessageBox.Show("You have to fill the TextBoxes..."
                 "WARNING", MessageBoxButtons.OK,MessageBoxIcon.Warning);
                  this.textboxFirstname.Focus();
     }
  }
  catch (Exception ex)
  {
     MessageBox.Show("Error in inserting new record : " + 
        ex.Message, "Insert Error", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
     fnRefreshDataSet();
  } //try-catch
}


Den Orginal-Beitrag findes Du hier.
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: So 29.01.06 18:26 
wenn du mit DataSets arbeitest wird dir für simple Einsatzfälle eigentlich alle Arbeit abgenommen...
Ein Fill des DataAdapters wird alle Datensätze, die er eingefügt hat als unverändert markieren. Jede Änderung danach markiert sie als Neu, gelöscht oder geändert.
Wenn du nun Update des DataAdapters ausführst werden die geänderten Daten zurückgeschrieben...