Thursday, September 11, 2008

Om: Symbol of the Absolute

\




"The goal which all the Vedas declare, which all austerities aim at, and which men desire when they lead the life of continence … is Om. This syllable Om is indeed Brahman. Whosoever knows this syllable obtains all that he desires. This is the best support; this is the highest support. Whosoever knows this support is adored in the world of Brahma."
~ Katha Upanishad I


Om or Aum is of paramount importance in Hinduism. This symbol (as seen in the image on the right) is a sacred syllable representing Brahman, the impersonal Absolute of Hinduism — omnipotent, omnipresent, and the source of all manifest existence. Brahman, in itself, is incomprehensible; so a symbol becomes mandatory to help us realize the Unknowable. Om, therefore, represents both the unmanifest (nirguna) and manifest (saguna) aspects of God. That is why it is called pranava, to mean that it pervades life and runs through our prana or breath.


Om in Daily Life

Although Om symbolizes the most profound concepts of Hindu belief, it is in use daily. The Hindus begin their day or any work or a journey by uttering Om. The sacred symbol is often found at the head of letters, at the beginning of examination papers and so on. Many Hindus, as an expression of spiritual perfection, wear the sign of Om as a pendant. This symbol is enshrined in every Hindu temple premise or in some form or another on family shrines.
It is interesting to note that a newly born child is ushered into the world with this holy sign. After birth, the child is ritually cleansed and the sacred syllable Om is written on its tongue with honey. Thus right at the time of birth the syllable Om is initiated into the life of a Hindu and ever remains with him as the symbol of piety.



The Music of Om

Om is not a word but rather an intonation, which, like music, transcends the barriers of age, race, culture and even species. It is made up of three Sanskrit letters, aa, au and ma which, when combined together, make the sound Aum or Om. It is believed to be the basic sound of the world and to contain all other sounds. It is a mantra or prayer in itself. If repeated with the correct intonation, it can resonate throughout the body so that the sound penetrates to the centre of one's being, the atman or soul.
There is harmony, peace and bliss in this simple but deeply philosophical sound. By vibrating the sacred syllable Om, the supreme combination of letters, if one thinks of the Ultimate Personality of Godhead and quits his body, he will certainly reach the highest state of "stateless" eternity, states the Bhagavad Gita.



The Vision of Om

Om provides a dualistic viewpoint. On one hand, it projects the mind beyond the immediate to what is abstract and inexpressible. On the other hand, it makes the absolute more tangible and comprehensive. It encompasses all potentialities and possibilities; it is everything that was, is, or can yet be. It is omnipotent and likewise remains undefined.
The Power of Om

During meditation, when we chant Om, we create within ourselves a vibration that attunes sympathy with the cosmic vibration and we start thinking universally. The momentary silence between each chant becomes palpable. Mind moves between the opposites of sound and silence until, at last, it ceases the sound. In the silence, the single thought—Om—is quenched; there is no thought. This is the state of trance, where the mind and the intellect are transcended as the individual self merges with the Infinite Self in the pious moment of realization. It is a moment when the petty worldly affairs are lost in the desire for the universal. Such is the immeasurable power of Om.
How to Type it on your Computer

Try this! To get the Om symbol on your computer screen, open MS Word and key in backslash ( \ ) in Wingdings font. You will type in Om!


Courtesy : http://hinduism.about.com 

Thanks,
Nitin Sharma

DataSet,DataTable,Dataview & ArrayList Essentials

C# code for ASP.Net Convert DataSet to ArrayList


// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories", mySQLconnection);mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);


// create an instance for ArrayList

ArrayList myArrayList = new ArrayList();

// foreach loop to read each DataRow of DataTable stored inside the DataSet

foreach

(DataRow dRow in myDataSet.Tables[0].Rows)
{ // add DataRow object to ArrayList
myArrayList.Add(dRow);
}


Above C# code shows how to convert DataSet to ArrayList. Add function of ArrayList accepts the parameter as object type. DataRow object has been passed in the above example to the Add function of ArrayList to store it in the collection.
Now the next step is also necessary to retrieve the values of columns stored in each row added to the ArrayList collection. Following C# code shows how to retrieve the ArrayList item as object, then convert it to DataRow and read the column value to display it on the ASP.Net web page:

// foreach loop to get each item of ArrayList foreach (Object objRow in myArrayList)
{ Response.Write(((DataRow)objRow)[ "categoryId" ].ToString() + " " + ((DataRow)objRow)[ "categoryName" ].ToString() + "
");
}





C# Code for ASP.Net Convert DataSet to DataView


// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories", mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;

SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);

DataSet myDataSet = new DataSet();

mySqlAdapter.Fill(myDataSet);



// Convert DataSet to DataView using DefaultView property associated with DataTable stored inside the DataSet
DataView dView = myDataSet.Tables[0].DefaultView;

You can bind the initialized object of DataView class with ASP.Net data presentation control such as GridVew, DataList or repeater to display the data on ASP.Net web page.
E.g.:
GridView1.DataSource = dView;
GridView1.DataBind();

C# Code for ASP.Net Convert ArrayList to Array


// ArrayList class object

ArrayList arrlist = new ArrayList();
// add items to arrlist collection using Add method

arrlist.Add("item 1");

arrlist.Add("item 2");

arrlist.Add("item 3");

arrlist.Add("item 4");

arrlist.Add("item 5");
// ToArray function: converts the ArrayList collection to Array type

Array myArray = arrlist.ToArray(typeof(string));
for (int i = 0; i <>

{

Response.Write(myArray.GetValue(i) + "
");

}
Response.Write("
");

arrlist.Clear();

arrlist.Add(1);

arrlist.Add(2);

arrlist.Add(3);

arrlist.Add(4);

arrlist.Add(5);
// ToArray function: converts the ArrayList collection to Array type

myArray = arrlist.ToArray(typeof(int));
for (int i = 0; i <>

{

Response.Write(myArray.GetValue(i) + "
");

}

You can also convert the ArrayList collection to array type using ToArray function without passing the System.Type parameter, this will convert the ArrayList collection to object[] array type. In the above C# sample code arrlist.Clear() method is used to remove all the items stored in the ArrayList collection to reuse it for adding integer type items to understand the System.Type parameter passed to the ToArray function.

C# Code for ASP.Net Convert DataSet to DataTable

C# Code for ASP.Net Convert DataSet to DataTable

// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories", mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;

SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);

DataSet myDataSet = new DataSet();

mySqlAdapter.Fill(myDataSet);


// Convert DataSet to DataTable by getting DataTable at first zero-based index of DataTableCollection
DataTable myDataTable = myDataSet.Tables[0];


Above C# code shows how to fill the DataSet with data retrieved from the SQL Database and convert it into a single DataTable. Next step is to display the data stored in DataTable. You can bind the DataTable directly to the ASP.Net Data presentation controls such as GridView, DataList or repeater to display the data. Or you can read the data stored in each DataRow using the C# foreach loop as following:

// foreach loop to get each DataRow of DataTable retrieved from DataSet
foreach (DataRow dRow in myDataTable.Rows)
{ Response.Write(dRow[ "categoryId" ].ToString() + " " + dRow[ "categoryName" ].ToString() + "
");

}

Wednesday, September 10, 2008

Adding Relations in DataSet

using System;
using System.Data;
using System.Data.SqlClient;
namespace Microsoft.AdoNet.DataSetDemo
{
class NorthwindDataSet
{
static void Main()
{
string connectionString = GetConnectionString();
ConnectToData(connectionString);
}


private static void ConnectToData(string connectionString)
{
//Create a SqlConnection to the Northwind database.
using (SqlConnection connection = new SqlConnection(connectionString))
{

//Create a SqlDataAdapter for the Suppliers table.
SqlDataAdapter adapter = new SqlDataAdapter();
// A table mapping names the DataTable.
adapter.TableMappings.Add("Table", "Suppliers");

// Open the connection.
connection.Open();

// Create a SqlCommand to retrieve Suppliers data.
SqlCommand command = new SqlCommand( "SELECT SupplierID, CompanyName FROM dbo.Suppliers;", connection);
command.CommandType = CommandType.Text;

// Set the SqlDataAdapter's SelectCommand.
adapter.SelectCommand = command;

// Fill the DataSet.
DataSet dataSet = new DataSet("Suppliers");
adapter.Fill(dataSet);


// Create a second Adapter and Command to get
// the Products table, a child table of Suppliers.

SqlDataAdapter productsAdapter = new SqlDataAdapter(); productsAdapter.TableMappings.Add("Table", "Products");
SqlCommand productsCommand = new SqlCommand( "SELECT ProductID, SupplierID FROM dbo.Products;", connection);
productsAdapter.SelectCommand = productsCommand;


// Fill the DataSet.

productsAdapter.Fill(dataSet);

// Close the connection.
connection.Close();

// Create a DataRelation to link the two tables
// based on the SupplierID.

DataColumn parentColumn = dataSet.Tables["Suppliers"].Columns["SupplierID"];
DataColumn childColumn = dataSet.Tables["Products"].Columns["SupplierID"];
DataRelation relation = new System.Data.DataRelation("SuppliersProducts", parentColumn, childColumn);
dataSet.Relations.Add(relation);
Console.WriteLine( "The {0} DataRelation has been created.", relation.RelationName);

}
}
static private string GetConnectionString()

{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.

return "Data Source=(local);Initial Catalog=Northwind;" + "Integrated Security=SSPI";

}
}
}


Thanks,
Nitin Sharma
Happy Coding...................!!!!!!

Tuesday, September 9, 2008

DataTable Explored

To create a DataTable, you need to use System.Data namespace, generally when you create a new class or page, it is included by default by the Visual Studio. Lets write following code to create a DataTable object. Here, I have pased a string as the DataTable name while creating DataTable object



// instantiate DataTable
DataTable dTable = new DataTable("Dynamically_Generated");


Creating Columns in the DataTable
To create column in the DataTable, you need to use DataColumn object. Instantiate the DataColumn object and pass column name and its data type as parameter. Then call add method of DataTable column and pass the DataColumn object as parameter.

// create columns for the DataTable
DataColumn auto = new DataColumn("AutoID", typeof(System.Int32));
dTable.Columns.Add(auto);
// create another column
DataColumn name = new DataColumn("Name", typeof(string));
dTable.Columns.Add(name);
// create one more column
DataColumn address = new DataColumn("Address", typeof(string));
dTable.Columns.Add(address);


Specifying AutoIncrement column in the DataTable
To specify a column as AutoIncrement (naturally it should be an integer type of field only), you need to set some properties of the column like AutoIncrement, AutoIncrementSeed. See the code below, here I am setting the first column "AutoID" as autoincrement field. Whenever a new row will be added its value will automatically increase by 1 as I am specified AutoIncrementSeed value as 1.

// specify it as auto increment field
auto.AutoIncrement = true;
auto.AutoIncrementSeed = 1;
auto.ReadOnly = true;


If you want a particular column to be a unique column ie. you don't want duplicate records into that column, then set its Unique property to true like below.


auto.Unique = true;

Specifying Primary Key column in the DataTable
To set the primary key column in the DataTable, you need to create arrays of column and store column you want as primary key for the DataTable and set its PrimaryKey property to the column arrays. See the code below.


// create primary key on this field
DataColumn[] pK = new DataColumn[1];
pK[0] = auto;
dTable.PrimaryKey = pK;




Populating data into DataTable
There are two ways to populate DataTable.
Using DataRow object
Look at the code below, I have created a DataRow object above the loop and I am assiging its value to the dTable.NewRow() inside the loop. After specifying columns value, I am adding that row to the DataTable using dTable.Rows.Add method.



// populate the DataTable using DataRow object
DataRow row = null;
for (int i = 0; i < 5; i++)
{
row = dTable.NewRow();
row["AutoID"] = i + 1;
row["Name"] = i + " - Ram";
row["Address"] = "Ram Nagar, India - " + i;
dTable.Rows.Add(row);
}




Instead of using the column name, you can use ColumnIndex too, however it is not suggested as you might want to add a column in the mid of the table then you will need to change your code wherever you have specified the index of the column. Same applies while reading or writing values into Database column.
Asiging the value of column using Arrays
In following code, I have specified the values of every column as the array separated by comma (,) in the Add method of the dTable.Rows.




// manually adding rows using array of values
dTable.Rows.Add(6, "Manual Data - 1", "Manual Address - 1, USA");
dTable.Rows.Add(7, "Manual Data - 2", "Manual Address - 2, USA");



Modifying data into DataTable
Modifying Row Data
To edit the data of the row, sets its column value using row index or by specifying the column name. In below example, I am updating the 3rd row of the DataTable as I have specified the row index as 2 (dTable.Rows[2]).



// modify certain values into the DataTable
dTable.Rows[2]["AutoID"] = 20;
dTable.Rows[2]["Name"] = "Modified";
dTable.Rows[2]["Address"] = "Modified Address";
dTable.AcceptChanges();




Deleting Row
To delete a row into DataTable, call the rows.Delete() method followed by AcceptChanges() method. AcceptChanges() method commits all the changes made by you to the DataTable. Here Row[1] is the index of the row, in this case 2nd row will be deleted as in collection (here rows collection) count start from 0.


// Delete row
dTable.Rows[1].Delete();
dTable.AcceptChanges();


Filtering data from DataTable
To filter records from the DataTable, use Select method and pass necessary filter expression. In below code, the 1st line will simply filter all rows whose AutoID value is greater than 5. The 2nd line of the code filters the DataTable whose AutoID value is greater than 5 after sorting it.



DataRow[] rows = dTable.Select(" AutoID > 5");
DataRow[] rows1 = dTable.Select(" AutoID > 5", "AuotID ASC");



Note that Select method of the DataTable returns the array of rows that matche the filter expression. If you want to loop through all the filtered rows, you can use foreach loop as shown below. In this code, I am adding all the filtered rows into another DataTable.



foreach (DataRow thisRow in rows)
{
// add values into the datatable
dTable1.Rows.Add(thisRow.ItemArray);
}




Sorting data of DataTable

There are two ways you can do this.
Using DataView
See the code below. I have created a DataView object by passing my DataTable as parameter, so my DataView will have all the data of the DataTable. Now, simply call the Sort method of the DataView and pass the sort expression. Your DataView object have sorted records now, You can either directly specify the Source of the Data controls object like GridView, DataList to bind the data or if you need to loop through its data you can use ForEach loop as below.


// Sorting DataTable
DataView dataView = new DataView(dTable);
dataView.Sort = " AutoID DESC, Name DESC";
foreach (DataRowView view in dataView)
{
Response.Write(view["Address"].ToString());
}



Using DataTable.Select() method
Yes, you can sort all the rows using Select method too provided you have not specified any filter expression. If you will specify the filter expression, ofcourse your rows will be sorted but filter will also be applied. A small drawback of this way of sorting is that it will return array of DataRows as descibed earlier so if you are planning to bind it to the Data controls like GridView or DataList you will have for form a DataTable by looping through because directly binding arrays of rows to the Data controls will not give desired results.


DataRow[] rows = dTable.Select("", "AutoID DESC");


Writing and Reading XmlSchema of the DataTable
If you need XmlSchema of the DataTabe, you can use WriteXmlSchema to write and ReadXmlSchema to read it. There are several overloads methods of both methods and you can pass filename, stream, TextReader, XmlReader etc. as the parameter. In this code, the schema will be written to the .xml file and will be read from there.


// creating schema definition of the DataTable
dTable.WriteXmlSchema(Server.MapPath("~/DataTableSchema.xml"));
// Reading XmlSchema from the xml file we just created
DataTable dTableXmlSchema = new DataTable();
dTableXmlSchema.ReadXmlSchema(Server.MapPath("~/DataTableSchema.xml"));



Reading/Writing from/to Xml
If you have a scenario, where you need to write the data of the DataTable into xml format, you can use WriteXml method of the DataTable. Note that WriteXml method will not work if you will not specify the name of the DataTable object while creating it. Look at the first code block above, I have passed "Dynamically_Generated" string while creating the instance of the DataTable. If you will not specify the name of the DataTable then you will get error as WriteXml method will not be able to serialize the data without it.



// Note: In order to write the DataTable into XML,
// you must define the name of the DataTable while creating it
// Also if you are planning to read back this XML into DataTable, you should define the XmlWriteMode.WriteSchema too
// Otherwise ReadXml method will not understand simple xml file
dTable.WriteXml(Server.MapPath("~/DataTable.xml"), XmlWriteMode.WriteSchema);
// Loading Data from XML into DataTable
DataTable dTableXml = new DataTable();
dTableXml.ReadXml(Server.MapPath("~/DataTable.xml"));



If you are planning to read the xml you have just created into the DataTable sometime later then you need to specify XmlWriteMode.WriteSchema too as the 2nd parameter while calling WriteXml method of the DataTable otherwise normally WriteXml method doesn't write schema of the DataTable. In the abscence of the schema, you will get error (DataTable does not support schema inference from Xml) while calling ReadXml method of the DataTable.


Thanks,
Happy Coding..!!!!!!!!!!!!!