Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 February 14th, 2007, 09:48 AM
Registered User
 
Join Date: Feb 2007
Location: Delhi, Delhi, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ami23
Default update datagridview

i hav a problem in datagridview
im using oledbadapter n ms access is my data base
nw im code is adding a new rows
bt its nt updating or deleting rows .. plz help me hw to use it


 
Old February 20th, 2007, 08:23 AM
Authorized User
 
Join Date: Nov 2006
Location: , , USA.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

This sounds like a similar problem that Yasho is experiencing. Have you configured the Update and Delete commands for your DataAdapter?



Best Regards,
Earl Francis
 
Old April 27th, 2007, 11:59 PM
vbn vbn is offline
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The DataAdapter is used for retrieving data from the database and populating the dataset. The DataAdapter class is also responsible for propagating changes back to the database. In other words, the DataAdapter is the connector class that sits between the disconnected and the connected parts of ADO.NET. The DataAdapter connects to a database using Connection object and then it uses Command objects to retrieve data from the database and to send data back to the database. With the exception of the DataReader class, all data access in ADO.NET goes through the data adapter. The DataAdapter is the bridge between the database and the dataset.

Instantiate DataAdapter

The below statements instantiate the DataAdapter objects. We need to instantiate DataAdapters one for the data we need to retrieve and one for update.

myAccountAdapter = New SqlDataAdapter(str_Account_Select, myConnection)

Setting the DataAdapter command properties.

The DataAdapter class has four properties:

1. SelectCommand
2. InsertCommand
3. UpdateCommand
4. DeleteCommand

Each of the property perform a specific operation on a database. Listed below are the four properties and their purpose.

1. SelectCommand
This read-write property returns or sets the SQL statement that will be used when rows are selected/retrieved from the data source.

2. InsertCommand.
This read-write property returns or sets the SQL statement that will be used when rows are inserted in to the data source.

3. UpdateCommand
This read-write property returns or sets the SQL statement that will be used when rows are updated in the data source.

4. DeleteCommand.
This read-write property returns or sets the SQL statement that will be used when rows are deleted from the data source. When the DataAdapter needs to retrieve or send data to and from the database, it uses Command objects which must be specified. We specify the command objects for selecting, updating, and deleting rows in the database. This is done by creating command objects, and then assigning them to the appropriate DataAdapter property: SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand are shown below.

myAccountAdapter.SelectCommand = comAccountSelect
myAccountAdapter.InsertCommand = comAccountInsert
myAccountAdapter.DeleteCommand = comAccountDelete
myAccountAdapter.UpdateCommand = comAccountUpdate

Add Update Command parameters.

comAccountUpdate.Parameters.Add("@id", SqlDbType.Char, 6, "AccountCode")
comAccountUpdate.Parameters.Add("@name", SqlDbType.Char, 30, "AccountName")

Add Delete Command parameters.

comAccountDelete.Parameters.Add("@id", SqlDbType.Char, 6, "AccountCode")

Here is the Updating the database using DataAdapter

The statement myAccountAdapter.Update(myAccountDataset, “AccountsTable”) updates the AccoutsTable.

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    myAccountAdapter.Update(myAccountDataset, "AccountsTable")
    myAccountDataset.AcceptChanges()
    MsgBox("Updation is over")
End Sub
End Class

Database programming usingVisual Basic 2005





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Data in Datagridview munmin2000 Visual Basic 2005 Basics 1 November 5th, 2007 03:27 AM
How do i Update data through a datagridview jazzydonald VB How-To 0 October 26th, 2007 02:52 AM
DatagridView in C# velan C# 2005 0 June 8th, 2007 09:25 PM
DataGridView Update Problem bipulbasakdhaka Visual Basic 2005 Basics 0 November 6th, 2006 04:31 AM
Update a DataGridView without CommandBuilder sfx ADO.NET 1 August 4th, 2006 05:14 AM





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