Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 22nd, 2004, 06:14 AM
Registered User
 
Join Date: Nov 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataSet and OleDbDataAdapter ?

It was said that any changes in DataSet will be sent to the datebase when you call the method OleDbDataAdaper.update().
But I got the problem!
It seems you need to have UpdateCommand associated in order to finish the updating.

I need help :(
 
Old November 22nd, 2004, 08:09 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
there are two ways for updating your database using dataset objects.
1-using CommandBuilder objects(like OleDbCommandBuilder,SqlCommandBuilder,...)
2-using UpdateCommand(as you said)
when you use dataset objects,it's better to use method one because you can simply change your dataset in disconnected environment and then simply update it,(you are not responsible for sending essential queries,CommandBuilder object sends them for you)
this example could clarify that more,
Code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
  Dim dstPubs As DataSet
  Dim conPubs As SqlConnection
  Dim dadTitles As SqlDataAdapter
  Dim dtblTitles As DataTable
  Dim drowTitle As DataRow
  Dim objCommandBuilder As New SqlCommandBuilder

  ' Grab Titles Table
  dstPubs = New DataSet()
  conPubs = New SqlConnection( "Server=localhost;Database=Pubs;UID=sa;PWD=secret" )
  dadTitles = New SqlDataAdapter( "Select * from Titles", conPubs )
  dadTitles.Fill( dstPubs, "Titles" )
  dtblTitles = dstPubs.Tables( "Titles" )

  ' Display Original Titles Table
  dgrdOriginalTitles.DataSource = dstPubs
  dgrdOriginalTitles.DataBind()

  ' Add a Row
  drowTitle = dtblTitles.NewRow()
  drowTitle( "Title_id" ) = "xxxx"
  drowTitle( "Title" ) = "ASP.NET Unleashed"
  drowTitle( "Price" ) = 1200.00
  drowTitle( "Type" ) = "Mystery"
  drowTitle( "PubDate" ) = #12/25/1966#
  dtblTitles.Rows.Add( drowTitle )

  ' Delete the First Row
  dtblTitles.Rows( 0 ).Delete()

  ' Double the price of the Second Row
  drowTitle = dtblTitles.Rows( 2 )
  drowTitle( "Price" ) *= 2

  ' Generate the SQL Commands
  objCommandBuilder = New SqlCommandBuilder( dadTitles )

  ' Update Titles Table
  dadTitles.Update( dstPubs, "Titles" )

  ' Display New Titles Table
  dgrdNewTitles.DataSource = dstPubs
  dgrdNewTitles.DataBind()
End Sub

</Script>

<html>
<head><title>UpdateDataSet</title></head>
<body>

<h2>Original Titles Table</h2>
<asp:DataGrid
  id="dgrdOriginalTitles"
  Runat="Server" />

<h2>New Titles Table</h2>
<asp:DataGrid
  id="dgrdNewTitles"
  Runat="Server" />

</body>
</html>
HtH.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old November 22nd, 2004, 10:23 AM
Registered User
 
Join Date: Nov 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,mehdi62b
Thank you very much for your help!
With the method one you presented, I solved the problem perfectly :)







Similar Threads
Thread Thread Starter Forum Replies Last Post
OleDbDataAdapter Problem RAnderson14 Pro VB Databases 0 April 11th, 2008 10:29 AM
OleDbDataAdapter Help mirage456 General .NET 1 July 5th, 2007 02:11 PM
database paging using asp table+ oledbdataadapter yamensaleh ASP.NET 2.0 Basics 0 January 27th, 2007 10:09 AM
OleDbDataAdapter myNameIsRon ADO.NET 2 June 9th, 2005 04:16 PM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.