473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Data Access Application Block

Does anyone have any experience of this functionality. I have started to
swap out my connection code for the std functionality within these dll's.
The data connection is fine, I can also run commands and return datasets.
However, the example they use to update a dataset is awful. It seems to
reply on hard coded sql store procedures (3 for each table) in order to
work. This is so much more unfriendly than the standard process of updating
a datarow or table. Any suggestions please.
Apr 10 '06 #1
2 2991

"Spam Catcher" <sp**********@rogers.com> wrote in message
news:Xn**********************************@127.0.0. 1...
"Chubbly Geezer" <ch************@newsgroup.nospam> wrote in
news:#Y**************@TK2MSFTNGP04.phx.gbl:
Does anyone have any experience of this functionality. I have started
to swap out my connection code for the std functionality within these
dll's. The data connection is fine, I can also run commands and return
datasets. However, the example they use to update a dataset is awful.
It seems to reply on hard coded sql store procedures (3 for each
table) in order to work. This is so much more unfriendly than the
standard process of updating a datarow or table. Any suggestions
please.

The data blocks work like the regular sql classes, except everything is
wrapped into one call... What hard coded SQL are you talking about?

The demo app uses the following code to update a dataset. It references 3
stored procedures for the insert, delete and update functionality. These
sp's have the table name hard coded in (i.e. Products).

I have realised that I can bypass these and drop the equivalent code direct
into my code (as I have done below). What I am now wanting to do, is wrap
up most of this functionality within a module and pass in the required
parameters. If I have to type all this every time, just for an update to a
dataset I'd be better off creating a datarow and updating that. It's easier
and has less code.

========================
Public Function UpdateProducts() As Integer

' Create the Database object, using the default database service. The

' default database service is determined through configuration.

Dim db As Database = DatabaseFactory.CreateDatabase()

Dim productsDataSet As DataSet = New DataSet

Dim sqlCommand As String = "Select ProductID, ProductName, CategoryID,
UnitPrice, LastUpdate " & _

"From Products"

Dim dbCommand As DbCommand = db.GetSqlStringCommand(sqlCommand)

Dim productsTable As String = "Products"

' Retrieve the initial data

db.LoadDataSet(dbCommand, productsDataSet, productsTable)

' Get the table that will be modified

Dim table As DataTable = productsDataSet.Tables(productsTable)

' Add a new product to existing DataSet

Dim addedRow As DataRow = table.Rows.Add(New Object() {DBNull.Value, "Sid's
product", 2, 25})

' Modify an existing product

table.Rows(0)("ProductName") = "Harry's Modified product"

' Delete an existing product

table.Rows(1).Delete()

' Establish our Insert, Delete, and Update commands

Dim insertCommand As DbCommand = db.GetSqlStringCommand("INSERT INTO
Products(ProductName, CategoryID, UnitPrice) VALUES(@ProductName,
@CategoryID, @UnitPrice)")

'Dim insertCommand As DbCommand = db.GetStoredProcCommand("AddProduct")

db.AddInParameter(insertCommand, "ProductName", DbType.String,
"ProductName", DataRowVersion.Current)

db.AddInParameter(insertCommand, "CategoryID", DbType.Int32, "CategoryID",
DataRowVersion.Current)

db.AddInParameter(insertCommand, "UnitPrice", DbType.Currency, "UnitPrice",
DataRowVersion.Current)

Dim deleteCommand As DbCommand = db.GetSqlStringCommand("Delete From
Products where ProductId = @ProductId")

'Dim deleteCommand As DbCommand = db.GetStoredProcCommand("DeleteProduct")

db.AddInParameter(deleteCommand, "ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current)

Dim updateCommand As DbCommand = db.GetSqlStringCommand("UPDATE Products SET
ProductName = @ProductName WHERE ProductID = @ProductID AND LastUpdate =
@LastUpdate")

'Dim updateCommand As DbCommand = db.GetStoredProcCommand("UpdateProduct")

db.AddInParameter(updateCommand, "ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current)

db.AddInParameter(updateCommand, "ProductName", DbType.String,
"ProductName", DataRowVersion.Current)

db.AddInParameter(updateCommand, "LastUpdate", DbType.DateTime,
"LastUpdate", DataRowVersion.Current)

' Submit the DataSet, capturing the number of rows that were affected

Dim rowsAffected As Integer = db.UpdateDataSet(productsDataSet, "Products",
insertCommand, updateCommand, deleteCommand, UpdateBehavior.Standard)

Return rowsAffected

End Function

========================

ALTER PROCEDURE [dbo].[AddProduct]

(

@ProductName nvarchar(50),

@CategoryID int,

@UnitPrice money

)

AS

INSERT INTO

Products (ProductName, CategoryID, UnitPrice)

VALUES

(@ProductName, @CategoryID, @UnitPrice)

SELECT

ProductID, ProductName, CategoryID, UnitPrice

FROM

Products

WHERE

ProductID = SCOPE_IDENTITY()

========================
Apr 10 '06 #2
Hi Chubbly,

The .NET Data Access Application Block methods deal with cases that a
DataSet is modified with multiple rows. The Update methods can update the
changes to database at one time. And it is not always suitable for all
cases. If you're just updating changes for one row, you can wrap the update
statements in your own code to achieve this.

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

Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Özgür Aytekin | last post by:
Hello NG Is DAAB 3.1 the offical replacement of Microsoft Data Access Application Block 2.0? DAAB 3.1 download:...
4
by: ad | last post by:
I want to develop DataBase application. How about Data Access Application Block? Is it useful?
0
by: ad | last post by:
I have used Data Application Access Block2 in my web application. Now I download the Library Data Access Application Block. and read the document. May be I am stupid, I can't migrate it to...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
1
by: EO | last post by:
I am trying to use the MSFT data access application block on 3 machines. Machine 1: Sandbox environment; I installed the application block with the msi. The Sqlhelper class compiles & runs...
3
by: Rachel | last post by:
Hi, I am using the data access application block successfully in our development environment, however when I deploy to our testing server as Private Assemblies I keep getting the following ...
6
by: Jonathan Crawford | last post by:
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473 Hi I have installed the enterprise library on a development machine and created a project on our webserver. When...
2
by: Tim::.. | last post by:
Can someone tell me how you change this code for an Oledb connection rather than SQL Server. The code currently uses Microsoft.Data.Access.Application.Block and the SQLHelper object... I need to...
6
by: Mukesh | last post by:
Hi I have Microsoft Enterprise Library 2005 installed on my local system. I m also using ASp.net 1.1 And C3 as coding language , I have MS Sql Server 2000. I am developing a web application...
3
by: Mukesh | last post by:
Hi all As per my earlier conversation with Ciaran (thx for reply) I have installed the MS APplication block on the server , when i ran Build Enterprise Library file and Install Services from...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.