Saturday, August 13, 2011

Creating a Simple XML Document ASP.net

namespace WriteToXML
{
using System;
using System.Xml;
///
/// Summary description for Class1.
///

public class Class1
{
public Class1()
{
}
public static int Main(string[] args)
{
try
{
// Creates an XML file is not exist
XmlTextWriter writer = new XmlTextWriter("C:\\temp\\xmltest.xml", null);
// Starts a new document
writer.WriteStartDocument();
//Write comments
writer.WriteComment("Commentss: XmlWriter Test Program");
writer.WriteProcessingInstruction("Instruction","Person Record");
// Add elements to the file
writer.WriteStartElement("p", "person", "urn:person");
writer.WriteStartElement("LastName","");
writer.WriteString("Chand");
writer.WriteEndElement();
writer.WriteStartElement("FirstName","");
writer.WriteString("Mahesh");
writer.WriteEndElement();
writer.WriteElementInt16("age","", 25);
// Ends the document
writer.WriteEndDocument();
}
catch (Exception e)
{
Console.WriteLine ("Exception: {0}", e.ToString());
}
return 0;
}
}
}









Write a LINQ query for a dataset

Public Class Test
Shared Sub main()
'Data set to store the value
Dim dset As New DataSet()

'Data table
Dim dt As New DataTable

'Adding columns to data table
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Address", GetType(String))

'Adding rows to the data table
dt.Rows.Add("Asha", "1", "Tumkur")
dt.Rows.Add("Usha", "2", "Bangalore")
dt.Rows.Add("Ashok", "3", "")
dt.Rows.Add("", "4", "Mysore")
dt.Rows.Add("", "5", "")

'Adding data table to the Data set
dset.Tables.Add(dt)


'LINQ to get required data
Dim DataWithName = From detail In dset.Tables(0) Where detail.Item("Name") IsNot String.Empty Select detail
Dim DataWithOutName = From detail In dset.Tables(0) Where detail.Item("Name") Is String.Empty Select detail

Dim DataWithAddress = From detail In dset.Tables(0) Where detail.Item("Address") IsNot String.Empty Select detail
Dim DataWithotAddress = From detail In dset.Tables(0) Where detail.Item("Address") Is String.Empty Select detail

'Displying the result
For Each rows As DataRow In DataWithName
Console.WriteLine(rows.Item("Name"))
Next

Console.ReadLine()
End Sub

End Class

Using LINQ with ASP.NET

Step 1: Creating your first ASP.NET page using LINQ

Create a new page called Step1.aspx. Within the .aspx page add a GridView control like so:



using System;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Query;

public partial class Step1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string[] cities = { "London", "Amsterdam", "San Francisco", "Las Vegas",

"Boston", "Raleigh", "Chicago", "Charlestown",

"Helsinki", "Nice", "Dublin" };

GridView1.DataSource = from city in cities

where city.Length > 4

orderby city

select city.ToUpper();

GridView1.DataBind();

}

}


LISQ Query with Where


using System;

using System.Query;

public partial class Data_Data2 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Northwind db = new Northwind();

GridView1.DataSource = from x in db.Suppliers

where x.Country == "USA"

orderby x.Country

select new {

x.CompanyName,

x.Country,

x.Products

};

GridView1.DataBind();

}

}

ابن انشا : 1927ء - 1978ء: دل عشق میں‌بے مایاں ، سودا ہو تو ایسا ہو

ابن انشا : 1927ء - 1978ء: دل عشق میں‌بے مایاں ، سودا ہو تو ایسا ہو