473,511 Members | 14,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating Dataset Column Value ...

3 New Member
Guys,

I am looping thru a dataset and need to update rows' columns based on the ColumnName value. I get this far but I'm unsure of how to update that actual columns value with the new value. Code follows:

string sDate = (Thread.CurrentThread.CurrentCulture.DateTimeForma t.ShortDatePattern.ToString());

string BritishDate;
string USDate;

if (sDate != "MM/dd/yyyy")
{
foreach (DataRow drItemPlan in dsItemDemand.Tables[0].Rows)
{
BritishDate = drItemPlan["exp_date"].ToString();
USDate = DateTime.Parse(BritishDate).ToString("MM/dd/yyyy");

foreach (DataColumn col in dsItemDemand.Tables[0].Columns)
{
if (col.ColumnName == "exp_date")
{
//UPDATE THE COLUMN VALUE TO EQUAL USDate
}
}

}
}


I'm new to C# and I'm having some issues with the fact a dataset is an object and how to then maniuplate that object's column and/or row values.

Thanks.
Mar 20 '08 #1
3 1493
nateraaaa
663 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. if (sDate != "MM/dd/yyyy")
  2. {
  3. foreach (DataRow drItemPlan in dsItemDemand.Tables[0].Rows)
  4. {
  5. BritishDate = drItemPlan["exp_date"].ToString();
  6. USDate = DateTime.Parse(BritishDate).ToString("MM/dd/yyyy");
  7. //you will need to call an update stored procedure to update the the value in the database. Pass USDate to the proc as a parameter and update the exp_date value for each row.
  8. }
  9. }
Nathan
Mar 20 '08 #2
hauschild
3 New Member
The application has a back end handled by a Progress database. The current dataset gets built as a user builds an Infragistics grid of data records.

What I need to do is update the value of the date field in the dataset so that it doesn't blow up the back end code - which it does now.

I am beginning to wonder if it isn't possible to update a dataset that already contains data and whether I should maybe base this entire process off looping thru the records in the grid versus looping thru the records of the dataset - or create a new record with the new value while deleting the old one.
Mar 20 '08 #3
hauschild
3 New Member
Guys,

I figured something out which works so far, although I'm certainly not experienced enough in the realm of C# to know if what I've created is actually accurate and almost as importantly, efficient. Here is what I did:

string sDate = (Thread.CurrentThread.CurrentCulture.DateTimeForma t.ShortDatePattern.ToString());

foreach (DataRow drItemPlan in dsItemDemand.Tables[0].Rows)
{
string CanuckDate = drItemPlan["exp_date"].ToString();

System.Threading.Thread.CurrentThread.CurrentCultu re = new System.Globalization.CultureInfo("en-CA");
DateTime dtCanuckDate = Convert.ToDateTime(CanuckDate);

System.Threading.Thread.CurrentThread.CurrentCultu re = new System.Globalization.CultureInfo("en-US");
dtCanuckDate = Convert.ToDateTime(dtCanuckDate.ToShortDateString( ));

dsItemDemand.Tables["ttitem_plan"].Rows[i]["exp_date"] = dtCanuckDate;
i++;
dsItemDemand.AcceptChanges();

}


Maybe this will help somebody else who is new to C#.

I shoudl also add why I needed to do this. Basically, the back end database is Progress, which was installed on the clients' machines in M/D/Y format(at least my guess). As a result, all date types would be expecting mm/dd/yyyy. A day like today (march 21, 2008) would make it choke because the front end would be sending 21/3/2008 (standard Canada date format) - Progress expects there to be a numberic value between 1-12 in the first two byte postions, but obviously 21 is greater than 12, hence the minor mushroom cloud and a failed database update. Reinstalling Progress was not an option, so this was the option that made the most sense. The only probelm with this route is that every screen of our app (while not many) which may see a user updating a date value will need to be addressed.
Mar 21 '08 #4

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

Similar topics

3
12997
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
5
2013
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...
14
2104
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...
4
2360
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
3
8903
by: RSH | last post by:
Hi, I have a situation in where i have two instances of SQL server, the first is our Production Environment, the second is our Development environment. Both servers contain the same databases...
13
11756
by: Dale Harris | last post by:
I'm getting really strange behaviour where the data source RowState is not being updated to modified in some circumstances. I place my controls on a form, bind them through a BindingSource control...
5
1963
by: JimmyKoolPantz | last post by:
Situation: I am writing a program that opens up a data file (file ext .dbf), imports the information into a dataset. The program also, searches through the dataset for key words ("company...
3
1329
by: iKiLL | last post by:
Hi all The Code is below but i will give you a brief over view first. I am using C#, SQL Mobile and the CF2.0 with Merge Replication. My Primary Keys are all "uniqueidentifier" types...
2
1137
by: Sid Price | last post by:
I have an application that has already been deployed and we need to add a new column to some of the tables in the application database. We are using an access database. We have a solution working...
0
7137
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...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
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...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5659
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,...
0
4734
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...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
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...

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.