J
J. Ouwehand
Hello, I'm a newbee to .net. I've created a typed dataset in VS. When I
insert a row, it shows that it's there but in fact the row is not committed
to the database. When I restart my app, the new row is gone. Could someone
help me out on this?
Here my proc that does the insert:
(note: i've created a new part (partial class) to the tableadapter so that
it's possible to set the transaction to the command that does the insert)
any help will be appreciated
private void btnMaakTestData_Click(object sender, EventArgs e)
{
int lAantal = int.Parse(cmbAantal.SelectedItem.ToString());
ProspectsTableAdapters.prospectTableAdapter lTA = new
prospectTableAdapter();
Properties.Settings settings = new Settings();
SqlConnection conn = new
SqlConnection(settings.CRMManagerConnectionString);
conn.Open();
lTA.Connection = conn;
long lMaxID = (long)lTA.MaxProspectId();
SqlTransaction trans =
conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
lTA.Transaction = trans; // sets insertcommand.transaction
try
{
for (int i = 1; i <= lAantal; i++)
{
long lID = lMaxID + i;
lTA.Insert(
lID,
"Prospect " + lID.ToString(),
"T.T.",
"van den",
"drs",
null,
"Van Benthemlaan",
"12",
"1212 EB",
"Hilversum",
null,
"Nederland",
DateTime.Now,
DateTime.Now);
}
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
trans.Commit();
MessageBox.Show("Klaar");
}
insert a row, it shows that it's there but in fact the row is not committed
to the database. When I restart my app, the new row is gone. Could someone
help me out on this?
Here my proc that does the insert:
(note: i've created a new part (partial class) to the tableadapter so that
it's possible to set the transaction to the command that does the insert)
any help will be appreciated
private void btnMaakTestData_Click(object sender, EventArgs e)
{
int lAantal = int.Parse(cmbAantal.SelectedItem.ToString());
ProspectsTableAdapters.prospectTableAdapter lTA = new
prospectTableAdapter();
Properties.Settings settings = new Settings();
SqlConnection conn = new
SqlConnection(settings.CRMManagerConnectionString);
conn.Open();
lTA.Connection = conn;
long lMaxID = (long)lTA.MaxProspectId();
SqlTransaction trans =
conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
lTA.Transaction = trans; // sets insertcommand.transaction
try
{
for (int i = 1; i <= lAantal; i++)
{
long lID = lMaxID + i;
lTA.Insert(
lID,
"Prospect " + lID.ToString(),
"T.T.",
"van den",
"drs",
null,
"Van Benthemlaan",
"12",
"1212 EB",
"Hilversum",
null,
"Nederland",
DateTime.Now,
DateTime.Now);
}
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
trans.Commit();
MessageBox.Show("Klaar");
}