Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Saving gridview data changes, ASP.NET VB grrrr...

views
     
TSgsrc
post Jan 30 2009, 10:28 AM, updated 17y ago

Casual
***
Junior Member
396 posts

Joined: Apr 2007
From: Penang, Malaysia



I wanted to save the whole changes done to the dropdownlist and the date, so when user clicked the SAVE button, the whole table will be saved, but I am having problem doing it. Can anyone help?
user posted image

I've tried the following but in vain. No update were done.
CODE
Dim i As Integer
While (i < GridView1.Rows.Count)
       GridView1.UpdateRow(i, False)
       i += 1
End While

Am I looking at the right place? Should I be saving the dataset instead of saving the gridview instead? Any help would be appreciated thanks.
unrealweapon
post Jan 30 2009, 10:32 AM

it's painful.
*****
Senior Member
865 posts

Joined: Jan 2008
From: Paradise City


QUOTE(gsrc @ Jan 30 2009, 10:28 AM)
I wanted to save the whole changes done to the dropdownlist and the date, so when user clicked the SAVE button, the whole table will be saved, but I am having problem doing it. Can anyone help?
user posted image

I've tried the following but in vain. No update were done.
CODE
Dim i As Integer
While (i < GridView1.Rows.Count)
       GridView1.UpdateRow(i, False)
       i += 1
End While

Am I looking at the right place? Should I be saving the dataset instead of saving the gridview instead? Any help would be appreciated thanks.
*
hi

check your code under the aspx file, u need update command (SQL) for ur UpdateRow to work.
if u do not have, i suggest u save the dataset.Datatable instead.
TSgsrc
post Jan 30 2009, 10:37 AM

Casual
***
Junior Member
396 posts

Joined: Apr 2007
From: Penang, Malaysia



QUOTE(unrealweapon @ Jan 30 2009, 10:32 AM)
hi

check your code under the aspx file, u need update command (SQL) for ur UpdateRow to work.
if u do not have, i suggest u save the dataset.Datatable instead.
*
I'm not using .aspx to bind the dataset so I'll have to skip that for the now.

As for the save dataset.dataTable part, do you mean using the code below?
CODE
           ds.Tables("ROSTERWEEKEND").AcceptChanges()


Kenneth85
post Jan 30 2009, 10:41 AM

Getting Started
**
Junior Member
208 posts

Joined: Feb 2007


QUOTE(unrealweapon @ Jan 30 2009, 10:32 AM)
hi

check your code under the aspx file, u need update command (SQL) for ur UpdateRow to work.
if u do not have, i suggest u save the dataset.Datatable instead.
*
i agree with u..
using dataset to store the stored procedure, make this ways easier...

Just load "selected details" into gridview, and when user click save, it will automatically update the database.

This post has been edited by Kenneth85: Jan 30 2009, 10:42 AM
unrealweapon
post Jan 30 2009, 10:44 AM

it's painful.
*****
Senior Member
865 posts

Joined: Jan 2008
From: Paradise City


QUOTE(gsrc @ Jan 30 2009, 10:37 AM)
I'm not using .aspx to bind the dataset so I'll have to skip that for the now.

As for the save dataset.dataTable part, do you mean using the code below?
CODE
           ds.Tables("ROSTERWEEKEND").AcceptChanges()

*
depending on how u do it,

for database <-> dataset, the must be a link, such as datatable adapter or binding


if u are declaring a dataset via code, most likely u need to loop ur dataset.
eg: dataset = " dataset something from sql"

AcceptChanges() wont help.

i strongly suggest using binding method. as this will help u alot coz binding method will reduce codes and sql.

if u view is combination of alot of 2 or more tables, u can still use binding method, write u update statement in an procedure, use ur store procedure in ur dataset, a simple loop to update ur data.

This post has been edited by unrealweapon: Jan 30 2009, 10:47 AM
TSgsrc
post Jan 30 2009, 10:46 AM

Casual
***
Junior Member
396 posts

Joined: Apr 2007
From: Penang, Malaysia



QUOTE(Kenneth85 @ Jan 30 2009, 10:41 AM)
i agree with u..
using dataset to store the stored procedure, make this ways easier...

Just load "selected details" into gridview, and when user click save, it will automatically update the database.
*
I wanted to save the whole gridview instead of row by row anyway. icon_rolleyes.gif

QUOTE(unrealweapon @ Jan 30 2009, 10:44 AM)
depending on how u do it,

for database <-> dataset, the must be  a link, such as datatable adapter or binding
if u are declaring a dataset via code, most likely  u need to loop ur dataset.
eg: dataset = " dataset something from sql"

AcceptChanges() wont help.

i strongly suggest using binding method. as this will help u alot coz binding method will reduce codes
*
Ok I'll try to work on it and see how it goes. icon_rolleyes.gif
unrealweapon
post Jan 30 2009, 10:49 AM

it's painful.
*****
Senior Member
865 posts

Joined: Jan 2008
From: Paradise City


QUOTE(gsrc @ Jan 30 2009, 10:46 AM)
I wanted to save the whole gridview instead of row by row anyway. icon_rolleyes.gif

*
saving row by row is waste of time and resources.

when use dataset.datatable binding, each modified row has a state. such as modified, deleted, new .. bla bla bla..

therefore, u can prevent same unmodified row from reupdate which save alot of resource when u have alot of records.

geekster129
post Jan 30 2009, 11:11 AM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



QUOTE(gsrc @ Jan 30 2009, 10:28 AM)
I wanted to save the whole changes done to the dropdownlist and the date, so when user clicked the SAVE button, the whole table will be saved, but I am having problem doing it. Can anyone help?

» Click to show Spoiler - click again to hide... «


I've tried the following but in vain. No update were done.
CODE
Dim i As Integer
While (i < GridView1.Rows.Count)
       GridView1.UpdateRow(i, False)
       i += 1
End While

Am I looking at the right place? Should I be saving the dataset instead of saving the gridview instead? Any help would be appreciated thanks.
*
Did some study on Gridview and found out that there's some SQL commands that you'll put together with the Gridview control declaration. I suspect that upon running the UpdateRow method, the SQL UPDATE associated to it might be incorrect. Check if that is correct.

This post has been edited by geekster129: Jan 30 2009, 11:11 AM
unrealweapon
post Jan 30 2009, 11:21 AM

it's painful.
*****
Senior Member
865 posts

Joined: Jan 2008
From: Paradise City


QUOTE(geekster129 @ Jan 30 2009, 11:11 AM)
Did some study on Gridview and found out that there's some SQL commands that you'll put together with the Gridview control declaration. I suspect that upon running the UpdateRow method, the SQL UPDATE associated to it might be incorrect. Check if that is correct.
*
yes.. u have to declare the update method.. u can even put store procedure as sql to do updates.
geekster129
post Jan 30 2009, 11:27 AM

Janitor
******
Senior Member
1,180 posts

Joined: Jan 2007
From: *awaiting GPS accuracy*



QUOTE(unrealweapon @ Jan 30 2009, 11:21 AM)
yes.. u have to declare the update method.. u can even put store procedure as sql to do updates.
*
I think stored procedure will make your code much cleaner and more maintainable. Besides, it is much more secure, because the SP is controlled on the DBMS side.
TSgsrc
post Jan 30 2009, 11:33 AM

Casual
***
Junior Member
396 posts

Joined: Apr 2007
From: Penang, Malaysia



I don't have permission to create Stored Proc T_T.... Anyway done with the Select Command, now trying the Update part...

 

Change to:
| Lo-Fi Version
0.0175sec    0.34    5 queries    GZIP Disabled
Time is now: 22nd December 2025 - 11:10 PM