Multiple Inserts with SQLDataSource

S

Steven Blair

I am looking for some advice on the following problem:

I am using a GridView and a SQLDataSource.

The problem is based around a Room Booking app I am currently writing.

When the user makes a booking, an entry must be written to the Booking
table, and x amount of entries to the BookingXref(the room keys are held
here)

How can I write muliple Inserts using a SQLDataSource in such a way that
I rollback any errors (is it possible to wrap many SQLDataSource.Inserts
in a transaction) or can someone suggest another way of doing this?

I would have used a Stored Procedure, but the rooms are variable.

Any help on this would appreciated.

Regards,

Steven
 
P

Pete Davis

Take a look at the SqlTransaction class. You get it by calling
SqlConnection.BeginTransaction() at the beginning of your series of updates.

Call SqlTransaction.RollBack() if there's an error.

When the connection closes, the transaction will commit, or you can
specifically call SqlTransaction.Commit().

Pete
 
S

Steven Blair

Yeah I have seen this class before, but the problem is how to I get this
to interact with my SQLDataSource :|

I was hoping to use this SQLDataSource and somehow manage the multiple
inserts.
 
P

Pete Davis

If you're talking about the SQLDataSourceControl included with WebMatrix, I
have no idea how it works or what it supports, but I suspect, if it's a
wrapper for the data access that it's probably not going to give you that
level of control. I could be wrong, but I just don't know anything about it.

Pete
 
S

Steven Blair

its the SQLDataSource for 2005. You drag it on your web form and can
bind a GridView to it. I just need to know how to handle a situation
where I need to make more than one INSERT statement.
 

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