Click here to Skip to main content
16,011,680 members
Home / Discussions / C#
   

C#

 
GeneralRe: Passing Value Types by Reference Pin
Salil Khedkar22-Dec-04 19:20
Salil Khedkar22-Dec-04 19:20 
GeneralProblem with Stored Procedure Pin
ronin177022-Dec-04 14:29
ronin177022-Dec-04 14:29 
GeneralRe: Problem with Stored Procedure Pin
Javier Lozano22-Dec-04 18:36
Javier Lozano22-Dec-04 18:36 
Generalproblem auto increment field Pin
Gedrain22-Dec-04 13:30
Gedrain22-Dec-04 13:30 
GeneralRe: problem auto increment field Pin
Skynyrd22-Dec-04 13:35
Skynyrd22-Dec-04 13:35 
GeneralRe: problem auto increment field Pin
Heath Stewart22-Dec-04 19:07
protectorHeath Stewart22-Dec-04 19:07 
GeneralRe: problem auto increment field Pin
Gedrain23-Dec-04 3:13
Gedrain23-Dec-04 3:13 
GeneralRe: problem auto increment field Pin
Heath Stewart23-Dec-04 4:59
protectorHeath Stewart23-Dec-04 4:59 
Once again, the following lines will not do what you think they will:
adapterProducts.InsertCommand.Transaction = connection.BeginTransaction();
adapterProducts.Update(dS.GetChanges(), "products");
adapterProducts.InsertCommand.Transaction.Commit();
If you read the documentation for OleDbTransaction you'll see that a connection must be open for the transaction to be effective, and as I told you before (and the documentation for DataAdapter.Update also states) the DataAdapter opens and closes the connection itself. Not only are you wasting CPU cycles on useless instructions, but you'll get a false sense of security that your update is transacted.

Besides, when using a transaction you need to add a call to Rollback in the catch block to be effective.

If you want to try this, open and close the connection yourself. The default implementation of DbDataAdapter (which extends DataAdapter and from which OleDbDataAdapter directly derives) will not re-open the connection, and it will not close the connection if it didn't opened it in the first place. Create a new OleDbTransaction and associate it with your OleDbCommands (read the documentation for OleDbTransaction because you're not using it correctly anyway). After Update complete commit it (Commit). In the catch block roll it back (Rollback).

After using the designer (VS.NET) to generate the commands for an OleDbDataAdapter (which I believe I recommended to you before - writing examples is always helpful) it's apparent that OLE DB does not support combined SQL expressions. Why? Probably because OLE DB is a generic API for accessing data via providers and to assume that a provider supports combined expressions would be faulty. What you'll need to do, instead, is to call DataAdapter.Fill to re-update the DataSet and/or contained DataTables (depending on how you call Fill.

To note, the SqlCommand does support combined expressions and, if you have a choice, would be better of using SQL Server 2000 or the "free" Microsoft Data Engine (MSDE) if you have a qualifying product - Visual Studio .NET being one of them (this gives you redistribution rights as well, but be sure to read the EULA). MSDE is SQL Server 2000 but supports limited connections (20, IIRC). This gives you access to stored procedures, transaction support, replication, and so much more.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralTextBox Pin
Aviv Halperin22-Dec-04 11:56
Aviv Halperin22-Dec-04 11:56 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 12:11
protectorHeath Stewart22-Dec-04 12:11 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:17
Aviv Halperin22-Dec-04 12:17 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 12:40
protectorHeath Stewart22-Dec-04 12:40 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:20
Aviv Halperin22-Dec-04 12:20 
GeneralRe: TextBox Pin
Skynyrd22-Dec-04 12:29
Skynyrd22-Dec-04 12:29 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:39
Aviv Halperin22-Dec-04 12:39 
GeneralRe: TextBox Pin
Skynyrd22-Dec-04 12:46
Skynyrd22-Dec-04 12:46 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 12:50
protectorHeath Stewart22-Dec-04 12:50 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 13:13
Aviv Halperin22-Dec-04 13:13 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 13:18
protectorHeath Stewart22-Dec-04 13:18 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 13:20
Aviv Halperin22-Dec-04 13:20 
GeneralRe: TextBox Pin
Matt Gerrans22-Dec-04 12:31
Matt Gerrans22-Dec-04 12:31 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:41
Aviv Halperin22-Dec-04 12:41 
GeneralRe: TextBox Pin
Heath Stewart22-Dec-04 12:43
protectorHeath Stewart22-Dec-04 12:43 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:49
Aviv Halperin22-Dec-04 12:49 
GeneralRe: TextBox Pin
Aviv Halperin22-Dec-04 12:51
Aviv Halperin22-Dec-04 12:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.