473,803 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3021

"Spam Catcher" <sp**********@r ogers.com> wrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Chubbly Geezer" <ch************ @newsgroup.nosp am> wrote in
news:#Y******** ******@TK2MSFTN GP04.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.GetSqlString Command(sqlComm and)

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(product sTable)

' 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).D elete()

' Establish our Insert, Delete, and Update commands

Dim insertCommand As DbCommand = db.GetSqlString Command("INSERT INTO
Products(Produc tName, CategoryID, UnitPrice) VALUES(@Product Name,
@CategoryID, @UnitPrice)")

'Dim insertCommand As DbCommand = db.GetStoredPro cCommand("AddPr oduct")

db.AddInParamet er(insertComman d, "ProductNam e", DbType.String,
"ProductNam e", DataRowVersion. Current)

db.AddInParamet er(insertComman d, "CategoryID ", DbType.Int32, "CategoryID ",
DataRowVersion. Current)

db.AddInParamet er(insertComman d, "UnitPrice" , DbType.Currency , "UnitPrice" ,
DataRowVersion. Current)

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

'Dim deleteCommand As DbCommand = db.GetStoredPro cCommand("Delet eProduct")

db.AddInParamet er(deleteComman d, "ProductID" , DbType.Int32, "ProductID" ,
DataRowVersion. Current)

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

'Dim updateCommand As DbCommand = db.GetStoredPro cCommand("Updat eProduct")

db.AddInParamet er(updateComman d, "ProductID" , DbType.Int32, "ProductID" ,
DataRowVersion. Current)

db.AddInParamet er(updateComman d, "ProductNam e", DbType.String,
"ProductNam e", DataRowVersion. Current)

db.AddInParamet er(updateComman d, "LastUpdate ", DbType.DateTime ,
"LastUpdate ", DataRowVersion. Current)

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

Dim rowsAffected As Integer = db.UpdateDataSe t(productsDataS et, "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
1849
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: http://www.gotdotnet.com/Community/Workspaces/viewuploads.aspx?id=c20d12b0-af52-402b-9b7c-aaeb21d1f431 We'll use for our online stock exchange game (www.borsagame.com) a data access application block with source code. But, we are not sure, which one is better. DAAB 3.1 or MS Data Access Application Block 2.0?
4
1909
by: ad | last post by:
I want to develop DataBase application. How about Data Access Application Block? Is it useful?
0
2229
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 Enterprise Library Data Access Application Block. The code below is the Data Application Access Block 2, How can I modified them? //---------------using Data Application Access Block
2
2215
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 access the database layer. However, the code works in a pretty cumbersome and ungeneric way. Basically every query, update, and insert has its own function. So you see a lot of functions like webService.InsertCustomer(name, age, phone); or...
1
1932
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 great! (Also the SqlhelperParameterCache class; I'll refer to them collectively as the SqlHelper class.) I'm using unmodified application block code in all cases. Machine 2: Development environment, different project
3
1731
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 Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
6
1951
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 I run a simple data access page I get an error message. Apparently
2
2517
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 use this with an access database! reader = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings("strConn"), CommandType.StoredProcedure, "rolesForUser", New OleDbParameter("@Username", User.Identity.Name))
6
4154
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 in which i am using data Access Application Block for data access. I have a remote web n data server with asp.net 1.1 support
3
1819
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 (batch files ) programme files menu it was asking for visual studio 2003 , I have only .net framework on the server how can i use the MS application block data access library on my server plz help... Mukesh Agarwal
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.