|
|
#1 |
|
Addicted Member
Join Date: Apr 03
Posts: 172
![]() |
ado.net datagridview update problem
I have been searching all day and have seen a lot of people with the same problem, but no answer. I just have a basic table that I show in a datagridview. I want the use to be able to update anything, click a button and the updates get sent back to the database. This was so easy with recordsets in old ADO. Please help, I am sooooo frustrated..
Private adStations As New OleDbDataAdapter Private Stations_Table As New DataTable() Dim CN As New OleDbConnection("PROVIDER=Microsoft.Jet.oledb.4.0;" & _ "data source=" & DB_PATH) adStations = New OleDbDataAdapter("SELECT * FROM stations", CN) Stations_Table = New DataTable(sStationsTable) ' === Populate a new data table and bind it to the BindingSource. adStations.Fill(Stations_Table) DataGridView_Stations.DataSource = Stations_Table ''=== user does his thing, click Update button ..... adStations.Update(Station_Table) '====> Errror Error is: Update requires valida updatecommand Thnaks |
|
|
|
|
|
#2 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 61,543
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: ado.net datagridview update problem
How easy something is or was with ADO is pretty much irrelevant isn't it? You're using VB.NET and ADO.NET and what you want to do is easy. The fact that you don't know how doesn't make ADO better, which is the implication of your words.
Also, note that the DataGridView has nothing whatsoever to do with ADO.NET. The DataGridView is a control for displaying data and allowing the user to interact with that data. The data itself can be from any source you like. The DataGridView cares nothing for whether it was retrieved and/or will be saved using ADO.NET, ADO or whatever. As to your issue, check out this thread for an explanation of how to retrieve and save data using ADO.NET.
__________________
![]() 2007-2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW* |
|
|
|
|
|
#3 |
|
Addicted Member
Join Date: Apr 03
Posts: 172
![]() |
Re: ado.net datagridview update problem
Thank you so much for your quick response and concern for my efforts. I have seen that thread and as you can see I am already doing exactly all what it says to do but I still get errors. I have been on this forum for years and have always recieved very kind and helpful advice. Your sense of sarcasm and callousness is like a breath of fresh air. I wish you luck on your next work deadline after working 60+ hours a week and on a holiday.
Cheers
|
|
|
|
|
|
#4 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 61,543
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: ado.net datagridview update problem
I have already provided the solution in my previous post. Your error message says that you don't have a valid UpdateCommand. The fourth and fifth code snippets in the thread I linked to previously demonstrate how to create a valid UpdateCommand, as well as a DeleteCommand and InsertCommand.
There was not a hint of sarcasm in that post. I was stating that how easy or not something was in VB6 is irrelevant to how easy or not it is to achieve the same end in VB.NET. The two are as good as different languages so reminiscing about how it was doesn't do anyone any good. Stating that something was easy in VB6 can have no relevance to a VB.NET discussion unless there's an implication that VB6 is better as a result. As a VB.NET developer that bugs me, especially as the equivalent functionality is by no means difficult to implement in VB.NET. Not knowing how to do something doesn't mean it's difficult. If by "callous" you mean not caring for the impact of my words then I can live with that. I stated my case and provided you the information you needed to solve your problem. That's what I'm here for. If you choose to take offence then that's up to you. None was specifically intended, but there was no specific effort made to ensure that none was taken either.
__________________
![]() 2007-2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW* |
|
|
|
|
|
#5 |
|
Addicted Member
Join Date: Apr 03
Posts: 172
![]() |
Re: ado.net datagridview update problem
Thanks again for response. I was not offended, just annoyed. Since, I have at times, been one of those lazy programmers wanting an easy answer. But not this time, I have been searching a lot, and I already went over that thread you gave me. It is of no use, first there is no CommandBuilder with OLEDB, and second, the examples you gave use precise commands for updating specific fields and records. I jsut want whatever was changed in the DataGrid to be updated back to the database table. So, sorry to waste your time, I will keep searching for a useful answer. FYI, I do prefer VB.NET, I can't stand working in VB6 anymore, I just found the original ADO a lot more user friendly.
Cheers |
|
|
|
|
|
#6 |
|
Addicted Member
Join Date: Apr 03
Posts: 172
![]() |
Re: ado.net datagridview update problem
Jiminy,
Maybe it is just my interpretation of the Update thing. I was under the assumption that the .UPDATE would take all the changes made in the datagridview and load them into the database table. All the examples I have seen use an SQL update command for specific fields. Do I actually have to see what rows have been affected, then update by SQL every field that I want to be altered, Which is basically every field in my case. If this is the way it works, then I can deal with it and will alter my code.??? THanks |
|
|
|
|
|
#7 |
|
New Member
Join Date: Apr 07
Posts: 3
![]() |
Re: ado.net datagridview update problem
Debbie,
This response probably qualifies for the blind leading the blind cliche, but I'm going to offer what I can. I'm a student of VB.NET and actually went over this stuff this morning in one of my lessons. So take this for what its worth. The way its being explained to me is you must first get the changes using the GetChanges method for whats been added, modified and deleted, (three sperate statments) then call the Update method sperately on all three of these as well. Does that make sense? And can someone verify that im not horribly mistaken or passing along dumbed down methodolgies for learning? |
|
|
|
|
|
#8 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 61,543
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: ado.net datagridview update problem
If you don't know what columns your database contains then there are simple ways to find out.
There are some but very few situations where you wouldn't know ahead of time what columns tables contain. How is it that you know the name of the table but not the names of the columns? There IS an OleDbCommandBuilder class that will do exactly the same job as the SqlCommandBuilder class used in the example I provided.
__________________
![]() 2007-2010 Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs MSDN "How Do I?" Videos: VB | C# VBForums Database Development FAQ My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW* Last edited by jmcilhinney; May 29th, 2007 at 06:19 PM. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|