Showing posts with label inserted. Show all posts
Showing posts with label inserted. Show all posts

Friday, March 9, 2012

Inserts not committing

A user entered 20 debit memos thru the application. For each db memo, 1 - th
e
data is inserted into two SQL Server 2000 tables, 2- a commit is issued
(Begin Trans / Commit Trans), 3 - a Select is used to retrieve data to
display on the db memo thru Crystal Reports and is printed. For each of the
20 entered, a db memo was printed but when the application closed, only data
for the first four db memos was saved / committed in the database. The other
16 had not been saved / committed in the database. We know the data for the
16 were inserted or else the Select would not have retrieved the data to
display and print the DB memo. There were no error messages and the
application did not crash. This happened only three times in 18 months and w
e
cannot duplicate the error. The commits are all processed in the same VB for
m
flow code. Anyone ever have a similar issue? Anyone have an idea on what
might have occurred? Thanx.Are you printing inside the transaction?
AMB
"Inserts not committing" wrote:

> A user entered 20 debit memos thru the application. For each db memo, 1 -
the
> data is inserted into two SQL Server 2000 tables, 2- a commit is issued
> (Begin Trans / Commit Trans), 3 - a Select is used to retrieve data to
> display on the db memo thru Crystal Reports and is printed. For each of th
e
> 20 entered, a db memo was printed but when the application closed, only da
ta
> for the first four db memos was saved / committed in the database. The oth
er
> 16 had not been saved / committed in the database. We know the data for th
e
> 16 were inserted or else the Select would not have retrieved the data to
> display and print the DB memo. There were no error messages and the
> application did not crash. This happened only three times in 18 months and
we
> cannot duplicate the error. The commits are all processed in the same VB f
orm
> flow code. Anyone ever have a similar issue? Anyone have an idea on what
> might have occurred? Thanx.

Wednesday, March 7, 2012

Inserting values and get the last ID recorded to use in another INSERT

I need to insert some values into a table and after that catch the ID inserted.

I set some input parameters in stored procedure and only one to get the @.id defined as output

SqlParameter paramIdPedido = new SqlParameter("@.APP_IDPEDIDO", SqlDbType.Int, 4);
paramIdPedido.Direction = ParameterDirection.Output;
cmd.Parameters.Add(paramIdPedido);

Do I have to run cmd.ExecuteNonQuery(); to record first what I need and after
run ExecuteReader: something like SqlDataReader dr = cmd.ExecuteReader();while (dr.Read()... to get the ID)

From stored procedure:

INSERT table(fields) VALUES(vars)
SELECT TOP 1 @.id = id FROM table ORDER BY id DESC

I must do all these steps or maybe is there anything less complex to do?

Thanks!

Hello Roberot,

Have a look at the following example:http://davidhayden.com/blog/dave/archive/2006/02/16/2803.aspx

Jeroen Molenaar.