Check the column is already exist or not, on alter the table, During the add a new column.
if Not exists (select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='tblMurli'
and COLUMN_NAME='My_NewColumn' )
Alter table tblMurli Add My_NewColumn numeric(18, 0)
Tuesday, November 24, 2009
Tuesday, November 17, 2009
List Generic Controls
public class Product
{
public Product()
{
//
// TODO: Add constructor logic here
//
}
private int number;
public int Number
{
get { return number; }
}
private string name;
public string Name
{
get { return name; }
}
public Product(int number, string name)
{
this.name = name;
this.number = number;
}
}
===============================================
// List
List list = new List();
list.Add(new Product(1,"Murli"));
list.Add(new Product(2,"Sanjay"));
list.Add(new Product(3,"Mahesh"));
list.Add(new Product(4,"Tom"));
List intlist = new List();
intlist.Add(1);
intlist.Add(2);
intlist.Add(5);
intlist.Add(7);
for (int i = 0; i < intlist.Count; i++)
{
lblMessage.Text += "
No " + i + " :" + intlist[i];
}
foreach (int layland in intlist)
{
lblMessage.Text += layland;
}
GridView1.DataSource = intlist;
GridView1.DataBind();
{
public Product()
{
//
// TODO: Add constructor logic here
//
}
private int number;
public int Number
{
get { return number; }
}
private string name;
public string Name
{
get { return name; }
}
public Product(int number, string name)
{
this.name = name;
this.number = number;
}
}
===============================================
// List
List
list.Add(new Product(1,"Murli"));
list.Add(new Product(2,"Sanjay"));
list.Add(new Product(3,"Mahesh"));
list.Add(new Product(4,"Tom"));
List
intlist.Add(1);
intlist.Add(2);
intlist.Add(5);
intlist.Add(7);
for (int i = 0; i < intlist.Count; i++)
{
lblMessage.Text += "
No " + i + " :" + intlist[i];
}
foreach (int layland in intlist)
{
lblMessage.Text += layland;
}
GridView1.DataSource = intlist;
GridView1.DataBind();
Tuesday, November 10, 2009
Write Xml File Via Sql
Comment everything from the aspx page and write below code in the code behind files
1.==================================
string Con = "Data Source="46\\SQLEXPRESS2008;User id=sa;password=murli;Initial Catalog=Murli";
XmlDocument xDoc = new XmlDocument();
XPathNavigator xPath = xDoc.CreateNavigator();
using (SqlConnection Conn = new SqlConnection(Con))
{
Conn.Open();
SqlCommand Cmd = new SqlCommand("Select * from Product As Products For Xml Auto,Elements", Conn);
using (XmlWriter xW = xPath.PrependChild())
{
xW.WriteStartElement("Products");
using (XmlReader xR = Cmd.ExecuteXmlReader())
{
xW.WriteNode(xR, true);
}
xW.WriteEndElement();
}
}
Response.ContentType = "text/xml";
xDoc.Save(Response.Output);
2.=================================
using System.IO;
using System.Text;
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
SqlConnection con = new SqlConnection("Data Source=MyDataSource\\SQLEXPRESS2008;Initial Catalog=Murli;User ID=sa;Password=murli");
con.Open();
string s = "select * from tblAnswer";
SqlCommand cmd = new SqlCommand(s, con);
SqlDataReader dr = cmd.ExecuteReader();
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("");
while (dr.Read())
{
sb.Append("");
sb.Append("" + dr[0].ToString() + "");
sb.Append("" + dr[1].ToString() + "");
sb.Append("");
}
sb.Append("");
StreamWriter stw = File.CreateText("D://mutest1.xml");
stw.WriteLine(sb.ToString());
stw.Close();
}
1.==================================
string Con = "Data Source="46\\SQLEXPRESS2008;User id=sa;password=murli;Initial Catalog=Murli";
XmlDocument xDoc = new XmlDocument();
XPathNavigator xPath = xDoc.CreateNavigator();
using (SqlConnection Conn = new SqlConnection(Con))
{
Conn.Open();
SqlCommand Cmd = new SqlCommand("Select * from Product As Products For Xml Auto,Elements", Conn);
using (XmlWriter xW = xPath.PrependChild())
{
xW.WriteStartElement("Products");
using (XmlReader xR = Cmd.ExecuteXmlReader())
{
xW.WriteNode(xR, true);
}
xW.WriteEndElement();
}
}
Response.ContentType = "text/xml";
xDoc.Save(Response.Output);
2.=================================
using System.IO;
using System.Text;
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
SqlConnection con = new SqlConnection("Data Source=MyDataSource\\SQLEXPRESS2008;Initial Catalog=Murli;User ID=sa;Password=murli");
con.Open();
string s = "select * from tblAnswer";
SqlCommand cmd = new SqlCommand(s, con);
SqlDataReader dr = cmd.ExecuteReader();
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("");
while (dr.Read())
{
sb.Append("");
sb.Append("" + dr[0].ToString() + "");
sb.Append("" + dr[1].ToString() + "");
sb.Append("");
}
sb.Append("");
StreamWriter stw = File.CreateText("D://mutest1.xml");
stw.WriteLine(sb.ToString());
stw.Close();
}
Monday, November 9, 2009
Read XML File from Javascript
For reading xml data using javascript we need to go to the following steps.
1. First create xml file File name called book.xml or anything else.
2. on the another file write the below code
============================book.xml=============================================
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
==================================================
================Page where want to display the xml data =============================
<head>
<script type="text/javascript">
function loadXmlData(FName)
{
try{ // Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{ // Mozila,Safari,Opera,etc
xmlDoc = document.implementation.createDocument("","",null);
}
catch(e){alert(e.message);}
}
try{
xmlDoc.async = false;
xmlDoc.load(FName);
return xmlDoc;
}
catch(e){alert(e.message);}
}
function get_firstChild(n)
{
y=n.firstChild;
while (y.nodeType!=1)
{
y=y.nextSibling;
}
return y;
}
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXmlData("books.xml");
var Count = xmlDoc.getElementsByTagName("title");
//alert(Count.length);
for(var z=0;z<Count.length-1;z++)
{
document.write(z+1+" "+Count[z].childNodes[0].nodeValue +"<br/>");
}
document.write("<hr/>");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
x=get_firstChild(xmlDoc.getElementsByTagName("book")[3]);
document.write(x.nodeName);
</script>
</body>
==================Output=====================
1 Everyday Italian
2 Harry Potter
3 XQuery Kick Start
<hr/>
Everyday Italian
Giada De Laurentiis
2005title
1. First create xml file File name called book.xml or anything else.
2. on the another file write the below code
============================book.xml=============================================
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
==================================================
================Page where want to display the xml data =============================
<head>
<script type="text/javascript">
function loadXmlData(FName)
{
try{ // Internet Explorer
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{ // Mozila,Safari,Opera,etc
xmlDoc = document.implementation.createDocument("","",null);
}
catch(e){alert(e.message);}
}
try{
xmlDoc.async = false;
xmlDoc.load(FName);
return xmlDoc;
}
catch(e){alert(e.message);}
}
function get_firstChild(n)
{
y=n.firstChild;
while (y.nodeType!=1)
{
y=y.nextSibling;
}
return y;
}
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXmlData("books.xml");
var Count = xmlDoc.getElementsByTagName("title");
//alert(Count.length);
for(var z=0;z<Count.length-1;z++)
{
document.write(z+1+" "+Count[z].childNodes[0].nodeValue +"<br/>");
}
document.write("<hr/>");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
x=get_firstChild(xmlDoc.getElementsByTagName("book")[3]);
document.write(x.nodeName);
</script>
</body>
==================Output=====================
1 Everyday Italian
2 Harry Potter
3 XQuery Kick Start
<hr/>
Everyday Italian
Giada De Laurentiis
2005title
Wednesday, November 4, 2009
Monday, October 26, 2009
Count number of active user in asp.net
global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["OnlineUsers"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
=============================================
Get data in page
lblMessage.Text = DateTime.Now.ToShortDateString();
lblMessage.Text += " " + Application["OnlineUsers"].ToString();
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["OnlineUsers"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
=============================================
Get data in page
lblMessage.Text = DateTime.Now.ToShortDateString();
lblMessage.Text += " " + Application["OnlineUsers"].ToString();
Friday, September 18, 2009
Encript Decript String In Asp.Net
public string Encrypt(string text) // public static string Encrypt(string text)
{
try
{
text = text.Trim();
byte[] encData_byte = new byte[text.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(text);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch
{
throw;
}
// return string.Empty;
}
public string Decrypt(string text) // public static string Decrypt(string text)
{
try
{
text = text.Trim();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(text);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result.Replace("\\","").Replace("\"","");
}
catch
{
throw;
// Handle Exception Here
}
// return string.Empty;
}
Call Encript Decript Finction In Code Behind file:-
string Id = Decrypt(Request["Id"]);
string Id = Encrypt("\"" + Ds.Tables[0].Rows[i]["MaterialID"].ToString() + "\"");
{
try
{
text = text.Trim();
byte[] encData_byte = new byte[text.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(text);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch
{
throw;
}
// return string.Empty;
}
public string Decrypt(string text) // public static string Decrypt(string text)
{
try
{
text = text.Trim();
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(text);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result.Replace("\\","").Replace("\"","");
}
catch
{
throw;
// Handle Exception Here
}
// return string.Empty;
}
Call Encript Decript Finction In Code Behind file:-
string Id = Decrypt(Request["Id"]);
string Id = Encrypt("\"" + Ds.Tables[0].Rows[i]["MaterialID"].ToString() + "\"");
Subscribe to:
Comments (Atom)