asked on
private void centrumOpslaanButtton_Click(object sender, EventArgs e)
{
centra[itemTeller] = new Centrum_oud();
centra[itemTeller].centrumId = int.Parse(centrumIdTextBox.Text);
centra[itemTeller].naam = centrumNaamTextBox.Text;
centra[itemTeller].plaats = centrumPlaatsTextBox.Text;
centra[itemTeller].banen = int.Parse(centrumBanenTextBox.Text);
itemTeller += 1;
positie = itemTeller - 1;
}
private void centrumCommitButton_Click(object sender, EventArgs e)
{
using (SqlCeConnection connection = new SqlCeConnection(connectString))
{
connection.Open();
// Start a local transaction.
SqlCeTransaction sqlTran = connection.BeginTransaction();
// Enlist the command in the current transaction.
SqlCeCommand command = connection.CreateCommand();
command.Transaction = sqlTran;
try
{
int rowsaffected = 0;
for (int i = 0; i < centra.Length; i += 1)
{
if (centra[i] != null)
{
command.CommandText = "INSERT INTO Centrum (centrumId, naam, plaats, banen) VALUES ";
command.CommandText += "(" + centra[i].centrumId + ", N'" + centra[i].naam + "', N'" + centra[i].plaats + "', " + centra[i].banen + ");\n";
rowsaffected += command.ExecuteNonQuery();
}
}
sqlTran.Commit();
centrumToonTextBox.Text = rowsaffected + " records zijn in de database opgeslagen\r\n";
for (int i = 0; i < centra.Length; i += 1)
{
centra[i] = null;
}
itemTeller = 0;
positie = - 1;
centrumIdTextBox.Text = "";
centrumNaamTextBox.Text = "";
centrumPlaatsTextBox.Text = "";
centrumBanenTextBox.Text = "";
}
catch (Exception ex)
{
centrumToonTextBox.Text = ex.Message + "\r\nDe records zijn niet in de database opgeslagen\r\n";
sqlTran.Rollback();
}
}
}
public class Field
{
string naam;
string type;
int length;
int tabIndex;
string text;
public Field(string naam, string type, int length, int tabIndex, string text)
{
this.naam = naam;
this.type = type;
this.length = length;
this.tabIndex = tabIndex;
this.text = text;
}
public Field(string naam, string text, int tabIndex)
{
this.naam = naam;
this.tabIndex = tabIndex;
this.text = text;
}
public string Naam
{
get { return naam; }
set { naam = value; }
}
public string Type
{
get { return type; }
set { type = value; }
}
public int Length
{
get { return length; }
set { length = value; }
}
public int TabIndex
{
get { return length; }
set { length = value; }
}
public string Text
{
get { return type; }
set { type = value; }
}
}
panel2Fields.Add(new Field(this.panel2.Controls[i].Name, this.panel2.Controls[i].Text, this.panel2.Controls[i].TabIndex));