Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Monday, February 14, 2011

use Xslt with Xml

XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.


//Xslt

The element element extracts the value of a selected node.

The element can be used to select the value of an XML element and add it to the output.

XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.



--------------------------------------------------------------------------------


?xml version="1.0" encoding="iso-8859-1"?>
!-- Edited by XMLSpy® -->
xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

xsl:template match="/">
html>
body>
h2>My CD Collection /h2>
table border="1">
tr bgcolor="#9acd32">
th>Title /th>
th>Artist /th>
/tr>
xsl:for-each select="catalog/cd">
tr>
td>
xsl:value-of select="title"/>
/td>
td>
xsl:value-of select="artist"/>
/td>
/tr>
/xsl:for-each>
/table>
/body>
/html>
/xsl:template>
/xsl:stylesheet>

//Xml






cd>
title>Bridge of Spies /title>
artist>T`Pau /artist>
country>UK /country>
company>Siren /company>
price>7.90 /price>
year>1987 /year>
/cd>
cd>
title>Private Dancer /title>
artist>Tina Turner /artist>
country>UK /country>
company>Capitol /company>
price>8.90 /price>
year>1983 /year>
/cd>
cd>
title>Midt om natten /title>
artist>Kim Larsen /artist>
country>EU /country>
company>Medley /company>
price>7.80 /price>
year>1983 /year>
/cd>
cd>
title>Pavarotti Gala Concert /title>
artist>Luciano Pavarotti /artist>
country>UK /country>
company>DECCA /company>
price>9.90 /price>
year>1991 /year>
/cd>
cd>
title>The dock of the bay /title>
artist>Otis Redding /artist>
country>USA /country>
company>Atlantic /company>
price>7.90 /price>
year>1987 /year>
/cd>
cd>
title>Picture book /title>
artist>Simply Red /artist>
country>EU /country>
company>Elektra /company>
price>7.20 /price>
year>1985 /year>
/cd>
cd>
title>Red /title>
artist>The Communards /artist>
country>UK /country>
company>London /company>
price>7.80 /price>
year>1987 /year>
/cd>
cd>
title>Unchain my heart /title>
artist>Joe Cocker /artist>
country>USA /country>
company>EMI /company>
price>8.20 /price>
year>1987 /year>
/cd>
/catalog>

Friday, February 11, 2011

Heap Vs Stack(Value Type(Stack) and Reference Type(Heap))

//Link for Stack Vs Heap
http://www.c-sharpcorner.com/uploadfile/rmcochran/csharp_memory01122006130034pm/csharp_memory.aspx


Stack vs. Heap: What's the difference?

The Stack is more or less responsible for keeping track of what's executing in our code (or what's been "called"). The Heap is more or less responsible for keeping track of our objects (our data, well... most of it - we'll get to that later.).

Think of the Stack as a series of boxes stacked one on top of the next. We keep track of what's going on in our application by stacking another box on top every time we call a method (called a Frame). We can only use what's in the top box on the stack. When we're done with the top box (the method is done executing) we throw it away and proceed to use the stuff in the previous box on the top of the stack. The Heap is similar except that its purpose is to hold information (not keep track of execution most of the time) so anything in our Heap can be accessed at any time. With the Heap, there are no constraints as to what can be accessed like in the stack. The Heap is like the heap of clean laundry on our bed that we have not taken the time to put away yet - we can grab what we need quickly. The Stack is like the stack of shoe boxes in the closet where we have to take off the top one to get to the one underneath it.

The Stack is self-maintaining, meaning that it basically takes care of its own memory management. When the top box is no longer used, it's thrown out. The Heap, on the other hand, has to worry about Garbage collection (GC) - which deals with how to keep the Heap clean (no one wants dirty laundry laying around... it stinks!).

What goes on the Stack and Heap?

We have four main types of things we'll be putting in the Stack and Heap as our code is executing: Value Types, Reference Types, Pointers, and Instructions.

Value Types:

In C#, all the "things" declared with the following list of type declarations are Value types (because they are from System.ValueType):

bool
byte
char
decimal
double
enum
float
int
long
sbyte
short
struct
uint
ulong
ushort
Reference Types:

All the "things" declared with the types in this list are Reference types (and inherit from System.Object... except, of course, for object which is the System.Object object):

class
interface
delegate
object
string
Pointers:

The third type of "thing" to be put in our memory management scheme is a Reference to a Type. A Reference is often referred to as a Pointer. We don't explicitly use Pointers, they are managed by the Common Language Runtime (CLR). A Pointer (or Reference) is different than a Reference Type in that when we say something is a Reference Type is means we access it through a Pointer. A Pointer is a chunk of space in memory that points to another space in memory. A Pointer takes up space just like any other thing that we're putting in the Stack and Heap and its value is either a memory address or null.

How is it decided what goes where? (Huh?)

Ok, one last thing and we'll get to the fun stuff.

Here are our two golden rules:

A Reference Type always goes on the Heap - easy enough, right?


Value Types and Pointers always go where they were declared. This is a little more complex and needs a bit more understanding of how the Stack works to figure out where "things" are declared.
The Stack, as we mentioned earlier, is responsible for keeping track of where each thread is during the execution of our code (or what's been called). You can think of it as a thread "state" and each thread has its own stack. When our code makes a call to execute a method the thread starts executing the instructions that have been JIT compiled and live on the method table, it also puts the method's parameters on the thread stack. Then, as we go through the code and run into variables within the method they are placed on top of the stack.

Wednesday, February 9, 2011

Static ,const and readonly

The value of a static readonly field is set at runtime; therefore, the value can be modified by the containing class. On the other hand, the value of a const field is set to a compile-time constant.

In the case of static readonly, the containing class is allowed to modify the value only:

in the variable declaration (via a variable initializer)
in the static constructor (or instance constructors for non-static)
Typically, static readonly is used either when the value is unknown at compile time or if the type of the field is not allowed in a const declaration.

Also, instance readonly fields are allowed.

Note: for reference types, in both cases—static and instance—the readonly modifier only prevents assignment of a new reference to the field. It does not specifically make the object pointed to by the reference immutable.
Example:-
class TestProgram
{
public static readonly Test test = new Test();

static void Main (string[] args)
{
test.Name = "Application";
test = new Test();
// Error: A static readonly field cannot
// be assigned to (except in a static constructor
// or a variable initializer).
}
}

class Test
{
public string Name;
}

Thursday, January 27, 2011

Sorting in array wihout using sort method

public static int[] SortArray(int[] characters, string Order)
{
if (Order == "Desc")
{
for (int i = 0; i < characters.Length; i++) { for (int j = i; j < characters.Length; j++) { if ((int)characters[j] > (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
else
{
for (int i = 0; i < characters.Length; i++)
{
for (int j = i; j < characters.Length; j++)
{
if ((int)characters[j] < (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
return characters;
}



///calling function

int[] characters = new int[] { 1,9,2,10,5 };
characters = Program.SortArray(characters, "Asc");
string str = "";
for (int i = 0; i < characters.Length; i++)
{
str += characters[i].ToString();
}
Console.WriteLine(str);
Console.ReadLine();

Tuesday, January 25, 2011

what is axapta

Microsoft Dynamics Axapta is a customizable, multiple language ,multiple currency enterprise resources planning or ERP solution. Microsoft Dynamics AX is completely integrated solution. It’s a web enabled and support Microsoft SQL Server and Oracle with customizable source code. You can modify the solution however and whenever you want.

Difference Between Axapta and Navision

Axapta & Navison, both are the application of Microsoft Dynamics.

Axapta uses X++ as programming language & Navison uses CSL.

There are many differences & one such difference is that Axapta has a payroll but Nav doesnot have payroll functionality.

Thursday, January 20, 2011

webservices Bind GridView

//connectionStrings>
add name="Master" connectionString="Data Source=SF-74\SQLEXPRESS;user id=;pwd=;Trusted_Connection=true" />

/connectionStrings>

//use some NameSpaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
using System.Data;

[WebMethod]
public XmlDocument GetDataFromDB()
{
string errorMessage = "";
XmlDocument myDatas = new XmlDocument();
//Connection string is stored in the web.config file as an appSetting
string connectionString = ConfigurationManager.ConnectionStrings["Master"].ConnectionString;
SqlConnection dbConnection = null;
// Open a connection to the database
try
{
dbConnection = new SqlConnection(connectionString);
dbConnection.Open();
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
if (errorMessage == "")
{
// Build an insert command
string SQL = "select * From sa";
SqlCommand GetCustomerCmd = new SqlCommand(SQL, dbConnection);

try
{
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = GetCustomerCmd;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "ProfileContact");
myDatas.LoadXml(custDS.GetXml());
dbConnection.Close();

}
catch (System.Exception ex)
{
errorMessage = ex.Message;

}
finally
{
dbConnection.Dispose();
}
}
return myDatas;
}


////////////aspx.cs

localhost.WebService2 proxy = new WebApplication1.localhost.WebService2();

protected void Page_Load(object sender, EventArgs e)
{
XmlDocument myServiceDoc = new XmlDocument();
System.Xml.XmlNode neNode;
//Adding the resulting XML from WebMethod to a user created XmlNode
neNode = proxy.GetDataFromDB();
//Creating a Dataset
DataSet myDataSet = new DataSet();
//The XmlNode is added to a byte[]
byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(neNode.OuterXml);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
//The XML is readed from the MemoryStream
myDataSet.ReadXml(ms);

GridView1.DataSource = myDataSet.Tables[0];
GridView1.DataBind();

//GridView1.DataSource = proxy.GetDataFromDB();
//GridView1.DataBind();

}