p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Editing Data in a DataView (http://p2p.wrox.com/showthread.php?t=40913)

thenextbillgates April 6th, 2006 03:45 PM

Editing Data in a DataView
 
I'm a beginner programmer in C# asp.NET and am currently working on a web portal as a college project. My question is, how do you change data that's in a dataview?

I have a dataset, and a dataview pointing to that dataset. (I'm away from the code at the moment, so syntax might not be perfect)

Code:

dv.table = ds.TABLE;
dv.sort = "POSITION";
dv.rowviewfilter = "ID>=" + variable;



Then I try to assign it to stuff:

Code:

dv[0]["POSITION"] = 125;


or read things out:

Code:

variable = dv[0]["ID"];


Also, I write the changes to the database using my own SQL statements.

But it doesn't seem to work. It compiles fine, but the changes don't appear on the page or in the database.

I hope this makes sense. Thanks for your help!




thenextbillgates April 7th, 2006 08:55 PM

I have the exact code now. It's a function that swaps two locations.

Code:

int HighLocation, LowLocation;
ModuleDataView.Table = UserInfoDSInstance.USERMODULE;           
ModuleDataView.Sort = "UMPOSITION";
ModuleDataView.RowFilter = "MID=" + CallingModule;
HighLocation = (int)ModuleDataView[0]["UMPOSITION"];
ModuleDataView.Table = UserInfoDSInstance.USERMODULE;           
ModuleDataView.Sort = "UMPOSITION";
ModuleDataView.RowFilter = "UMPOSITION>=" + HighLocation;
LowLocation = (int)ModuleDataView[1]["UMPOSITION"];
ModuleDataView[0]["UMPOSITION"] = LowLocation;
ModuleDataView[1]["UMPOSITION"] = HighLocation;
oracleUpdateCommand1.CommandText = "UPDATE USERMODULE SET UMPOSITION = " + LowLocation + " WHERE MID = " + (int)ModuleDataView[0]["MID"] + " AND USERID = '" + UserID + "'";
OracleConnection.Open();
oracleUpdateCommand1.ExecuteScalar();
oracleUpdateCommand1.CommandText = "UPDATE USERMODULE SET UMPOSITION = " + HighLocation + " WHERE MID = " + (int)ModuleDataView[1]["MID"] + " AND USERID = '" + UserID + "'";
oracleUpdateCommand1.ExecuteScalar();
OracleConnection.Close();

The changes are not being written to the database. Not sure why...


thenextbillgates April 10th, 2006 11:25 AM

anybody?? :(


thenextbillgates April 10th, 2006 09:40 PM

nevermind...figured it out.



All times are GMT -4. The time now is 01:05 AM.

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