ItemArray assignment not working as expected

This is a discussion on ItemArray assignment not working as expected within the C# Programming forums, part of the General Programming Boards category; Code: protected void processDS(DataSet ds) { DataTable dt; int i=0; batchLot = ds.Tables[0].Rows[0].ItemArray[0].ToString(); dt = ds.Tables[0]; foreach (DataRow dr in ...

  1. #1
    Slime Dragoon_42's Avatar
    Join Date
    Feb 2003
    Location
    Vancouver
    Posts
    90

    ItemArray assignment not working as expected

    Code:
    protected void processDS(DataSet ds)
            {
                DataTable dt;
                int i=0;            
                
                batchLot = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    for(i=0;i<dr.ItemArray.Length;i++)
                    {
                        dr.ItemArray.SetValue(dr.ItemArray[i].ToString().Replace("(M####)",batchLot),i);
                        dr.ItemArray.SetValue(dr.ItemArray[i].ToString().Replace("(DATE)",today.ToString("MMDDYY")),i);
                    }
                }
            }
    I'm looking in each field of each DataRow for the string values of either (M####) or (DATE) to change them to other things for display on a web page. Can anyone explain what kind of stupidity I've fallen into, please?

  2. #2
    Slime Dragoon_42's Avatar
    Join Date
    Feb 2003
    Location
    Vancouver
    Posts
    90
    Nevermind, I'm a friggin moron. Following code works as expected:
    Code:
    protected void processDS(DataSet ds)
            {
                DataTable dt;
                int i=0;            
                
                batchLot = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    for(i=0;i<dr.ItemArray.Length;i++)
                    {
                        if (dr.ItemArray.GetValue(i).ToString().Contains("(M####)"))
                            dr[i] = dr.ItemArray.GetValue(i).ToString().Replace("(M####)", batchLot);
                        if (dr.ItemArray.GetValue(i).ToString().Contains("(DATE)"))
                            dr[i] = dr.ItemArray.GetValue(i).ToString().Replace("(DATE)", today.ToString("MMddYY"));
                    }
                }
            }
    Thanks for your time, people!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help explaining test questions
    By Sentral in forum General Discussions
    Replies: 26
    Last Post: 11-09-2009, 10:10 PM
  2. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  3. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21