Typed dataset is not really committing data to database

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");
}
 
N

Nicholas Paldino [.NET/C# MVP]

Well, the code looks ok (I haven't tried to compile it, and can't, since
it's not a complete example, and I don't have an underlying data source).

Have you placed a breakpoint on the exception? I ask because the event
handlers for controls will swallow exceptions, and you won't see them. So
it's very possible an exception is occuring and you aren't seeing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top