studio NETSOULS

Applying Web To Your Business

This code is useful to transpose the datatable rows and columns.

   1: DataTable dtSource = new DataTable();
   2: protected void Page_Load(object sender, EventArgs e)
   3:    {
   4:     // Bind the source datatable from the database
   5:     dtSource = dataSource();
   6:    }
   7:  
   8: public DataTable FlipDataTable(GridView gvNew)
   9:     {
  10:         DataTable dataTable = new DataTable("dataTable");
  11:  
  12:         // create column
  13:         DataRow newRow;
  14:         for (int iRow = 0; iRow < dtSource.Columns.Count; iRow++)
  15:         {
  16:             newRow = dataTable.NewRow();
  17:  
  18:             newRow[0] = dtSource.Columns[iRow].ToString();
  19:  
  20:             for (int iCol = 1; iCol <= dtSource.Rows.Count; iCol++)
  21:             {
  22:                 newRow[iCol] = dtSource.Rows[iCol - 1][iRow];
  23:             }
  24:  
  25:             dataTable.Rows.Add(newRow);
  26:         }
  27:     }
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Lets suppose you have a data source in XML like:

   1: <Settings> 
   2:    <ElementCollection> 
   3:          <add key="SomeKey" value="SomeValue"> 
   4:          <add key="SomeKey" value="SomeValue"> 
   5:    </ElementCollection> 
   6: </Settings>


Now you want to edit the key and values with in the xml element collection.

<asp:XmlDataSource ID="configXmlDataSource" XPath="//add" runat="server" DataFile="~/settings.config"/>

Use the following code in the code-behind

   1: // In this code we are getting the Data Item values of the Rad Editor. On UpdateCommand Event we are getting the values of data row in an instance of hash.
   2: GridDataItem dataItem = (GridDataItem)e.Item; 
   3: Hashtable ht = new Hashtable(); 
   4: dataItem.ExtractValues(ht);
   5:  
   6: //Get the node values as per the selected key name: 
   7: XmlNode AppNode = XmlDataSource1.GetXmlDocument().SelectSingleNode( String.Format("//add[@key='{0}']", key)); 
   8:  
   9: //Now assign the new value of the Value attribute of the selected node:
  10: AppNode.Attributes["value"].Value = ht["value"];
  11:  
  12: //Finally we need to update the xml source file:
  13: configXmlDataSource.Save();
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

When a table's primary field is to auto increment with a seed and you are deleting the records from the table. Now you need to reset the primary field value to 1. The code given below is useful.
 

   1: DBCC CHECKIDENT (tblName, RESEED, 0)
  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

About Us

studio NETSOULS is a complete IT services company, offering strategy, design, development and implementation of the total solution for your web and IT initiatives. The solutions we provide, enables businesses to leverage leading edge technology to gain sustainable competitive advantages in today's marketplace.

We specialize in designing, developing and deploying the next generation of IT solutions including e-business solutions Read more...

Tags

This will be shown to users with no Flash or Javascript.

Contact Us

My status

Quote of the Day

Men are disturbed, not by the things that happen, but by their opinion of the things that happen

- Epictetus

NutritionVista

www.NutritionVista.com

Archives


Advertisements


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Log in