473,801 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating MS Access table from datagrid

18 New Member
I'm using VB.net 2003. I can delete a row in datagrid (dgTempTransact ion), but my MS Access table can't directly being updated. The row i deleted is still exist in my MS Access, but in my datagrid, it already being deleted.
The table name in my MS Access: tableTempTransa ction.

Here is my code for that part...i don't know where is the error. Please help me..... Thanks anyway.

Dim currManager As CurrencyManager

If IsNothing(DsTem pTransaction1) Then Exit Sub

currManager = CType(BindingCo ntext(DsTempTra nsaction1, "tableTempTrans action"), CurrencyManager )

'get the current row
Dim dRow As DataRow = CType(currManag er.Current, DataRowView).Ro w

'prompt to save changes
If MsgBox("Are you sure want to delete this item?", MsgBoxStyle.OKC ancel, "Hands On Programming") = MsgBoxResult.OK Then
'delete it from the dataset
dRow.Delete()

'get just the changed data
Dim dsChanged As DataSet = DsTempTransacti on1.GetChanges
'>>>Problem in this part...table inside MS Access cannot be updated.
Else
'reset the dataset
DsTempTransacti on1.RejectChang es()
End If
Aug 4 '07 #1
5 2954
kenobewan
4,871 Recognized Expert Specialist
It looks to me as though you deleting the row but not using sql to delete in access. HTH.
Aug 4 '07 #2
yzlin04
18 New Member
It looks to me as though you deleting the row but not using sql to delete in access. HTH.

but how to update it from the dataset by using SQL?
Aug 6 '07 #3
radcaesar
759 Recognized Expert Contributor
Until u use the DataAdapter.Upd ate() method, it will not update physically in the DB.

if (okayFlag)
{
// apply updates to the database
dataAdapter.Upd ate(dsChanges," PhoneNumbers");
// tell the user
MessageBox.Show ("Updated " + selectedRow["Phonenum"]);
Application.DoE vents();
// apply changes and refresh the listbox
dataSet.AcceptC hanges();
Fill_lb();
}
else // if any errors then throw out the changes
dataSet.RejectC hanges();
Aug 6 '07 #4
yzlin04
18 New Member
Until u use the DataAdapter.Upd ate() method, it will not update physically in the DB.

if (okayFlag)
{
// apply updates to the database
dataAdapter.Upd ate(dsChanges," PhoneNumbers");
// tell the user
MessageBox.Show ("Updated " + selectedRow["Phonenum"]);
Application.DoE vents();
// apply changes and refresh the listbox
dataSet.AcceptC hanges();
Fill_lb();
}
else // if any errors then throw out the changes
dataSet.RejectC hanges();



When i try to add the sample code u provided, the following error occured:

An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll

Additional information: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.



Code:

If IsNothing(DsTem pTransaction1) Then Exit Sub

currManager = CType(BindingCo ntext(DsTempTra nsaction1, "tableTempTrans action"), CurrencyManager )

'get the current row
Dim dRow As DataRow = CType(currManag er.Current, DataRowView).Ro w

'prompt to save changes
If MsgBox("Are you sure want to delete this item?", MsgBoxStyle.OKC ancel, "Hands On Programming") = MsgBoxResult.OK Then
'delete it from the dataset
dRow.Delete()

'get just the changed data
Dim dsChanged As DataSet = DsTempTransacti on1.GetChanges
'>>THIS LINE>> OleDbDataAdapte r1.Update(dsCha nged, "tableTempTrans action")
MessageBox.Show ("Delete Successful...", "Delete", MessageBoxButto ns.OK, MessageBoxIcon. Information)
Application.DoE vents()
DsTempTransacti on1.AcceptChang es()
Else
'reset the dataset
DsTempTransacti on1.RejectChang es()
MessageBox.Show ("Delete failed...", "Delete", MessageBoxButto ns.OK, MessageBoxIcon. Information)
End If
Aug 6 '07 #5
VBStarterKid
1 New Member
When i try to add the sample code u provided, the following error occured:

An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll

Additional information: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.



Code:

If IsNothing(DsTem pTransaction1) Then Exit Sub

currManager = CType(BindingCo ntext(DsTempTra nsaction1, "tableTempTrans action"), CurrencyManager )

'get the current row
Dim dRow As DataRow = CType(currManag er.Current, DataRowView).Ro w

'prompt to save changes
If MsgBox("Are you sure want to delete this item?", MsgBoxStyle.OKC ancel, "Hands On Programming") = MsgBoxResult.OK Then
'delete it from the dataset
dRow.Delete()

'get just the changed data
Dim dsChanged As DataSet = DsTempTransacti on1.GetChanges
'>>THIS LINE>> OleDbDataAdapte r1.Update(dsCha nged, "tableTempTrans action")
MessageBox.Show ("Delete Successful...", "Delete", MessageBoxButto ns.OK, MessageBoxIcon. Information)
Application.DoE vents()
DsTempTransacti on1.AcceptChang es()
Else
'reset the dataset
DsTempTransacti on1.RejectChang es()
MessageBox.Show ("Delete failed...", "Delete", MessageBoxButto ns.OK, MessageBoxIcon. Information)
End If


REPLY: I believe your problem could very well be that you have not adapted the OleCommandBuild er into your data adapter of your DataSet.
If you want to make your dataset to be able to make direct changes to the MS Access table, you need to enable the SQL UPDATE for your dataset and very important is that should be made before you apply the DataAdapter.Upd ate() method. To do this, OleCommandBuild er must be enabled to make yor DataSet open up the INSERT, UPDATE and DELETE options.

The tutorial on this, may help you:

http://vb-helper.com/howto_net_datagrid.html
Aug 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1695
by: Bryan Masephol | last post by:
Hi All I have a OleDbConnection as the "connection" below. I'm retriving a dataset from an access 2002 db and displaying it in a DataGrid. I'm making the connection to my access db file with this connection string "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename and everything is working fine with that. My table in the database is simple. 10 columns of text or numbers. No joining or anything else. It has a autonumber as...
1
3786
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a Yes/No value in Access. Using the OleDbCommand, if I do not consider the Yes/No field, the ExecuteNonQuery command, using my UPDATE SQL statement, updates the record correctly. However, if I put the Yes/No field into the mix, ExecuteNonQuery...
5
2041
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
1
1541
by: jason | last post by:
The guts of the below asp.net vb code was pieced together from another thread - all due credit to it's original author. Thank you! I've modified it to maintain a small local Microsoft 2000 access DB via a datagrid control. The add and delete functions work great, but the edit does not actually update the database. I put in some displays and apparently on the first item in the grid gets set during editing, all others come back empty???
0
1639
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables have a FK relationship on CAR_ID so the oracledataadapter1 select statement(CommandText) is: select car_master.car_id, car_master.year,car_master.vehicle,car_detail.car_id AS EXPR1,
10
5689
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1) DsStudentCourse1.AcceptChanges() i'm also wondering because w/ out AcceptChanges the data is still save into the database and it is now faster.
14
2134
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
13
5330
by: mfreeman | last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown below. All I do is loop through the records in the table and update them without making any changes. Out of 600 records, about 40 of them throw Concurrency violation errors in the update, and my GetAllColErrs function provides no output. In comparing the rows that throw errors with those that do not, I could find no pattern. It is obviously a bogus error, as the...
2
3322
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the CurrentChanged event of the BindingSource of the combobox to update the textbox. When selecting an item in the combobox or when selecting a row in the grid, it is updating the textbox correctly. The problem is when I apply a filter in the grid, and then...
0
9698
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
9556
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10295
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9105
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7593
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
6832
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
5618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4263
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
3
2961
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.