tag:blogger.com,1999:blog-84423122477788483192024-03-14T05:29:14.520+05:30Dot NET Basic ConceptsBasics of .NETAyyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8442312247778848319.post-21502468226403772952017-01-12T23:02:00.000+05:302017-01-12T23:02:19.203+05:30Regarding Tamil Farmers Real Stories<div dir="ltr" style="text-align: left;" trbidi="on">
Coming Soon..</div>
Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com3tag:blogger.com,1999:blog-8442312247778848319.post-27509046297623612002010-09-23T23:44:00.006+05:302011-12-03T14:15:06.153+05:30Superb Site For Dot Net<div dir="ltr" style="text-align: left;" trbidi="on"><div style="color: #a64d79;"><b><span class="Apple-style-span" style="font-size: x-large;"><i><span class="Apple-style-span"> Scintillating site</span></i></span></b></div><span class="Apple-style-span" style="color: #38761d;"><br />
</span><br />
<span class="Apple-style-span" style="color: #38761d;"> </span> <a href="http://nbende.wordpress.com/">http://nbende.wordpress.com/</a><br />
<br />
<a href="http://www.bangarraju.net/">http://www.bangarraju.net/</a><br />
<br />
<a href="http://sandblogaspnet.blogspot.com/">http://sandblogaspnet.blogspot.com/</a><br />
<br />
<div style="color: #741b47;"><b><i><span class="Apple-style-span" style="font-size: x-large;"><span class="Apple-style-span"> Recruitment Site</span></span></i></b></div><br />
<a href="http://www.presentjobs.com/%C2%A0">http://www.presentjobs.com/ </a><br />
<br />
www.chetanasforum.com<br />
<br />
<div style="color: #741b47;"><b><span class="Apple-style-span" style="font-size: x-large;"><i><span class="Apple-style-span"> Charity Site</span></i></span></b></div><br />
<div style="color: #351c75;"><b><i> <a href="http://www.bhookh.com/">http://www.bhookh.com</a></i></b><br />
<b><br />
</b></div><b><span class="Apple-style-span" style="font-size: x-large;"><i> Entertainment Site</i></span></b><br />
<a href="http://grooveshark.com/">http://grooveshark.com/</a><br />
<br />
<a href="http://www.imdb.com/">http://www.imdb.com/</a><br />
<br />
<br />
</div>Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com22tag:blogger.com,1999:blog-8442312247778848319.post-6783122013110213052010-05-11T13:01:00.003+05:302010-05-11T14:31:04.431+05:30Client Side Validation Web Form Using Java ScriptThe following Shows the Client Side Validation Web Form Using Java Script<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_dRN5PKJdoW4/S-kG4dEr7DI/AAAAAAAAAAc/P_UrZvYBTVA/s1600/reg.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="197" src="http://4.bp.blogspot.com/_dRN5PKJdoW4/S-kG4dEr7DI/AAAAAAAAAAc/P_UrZvYBTVA/s320/reg.jpeg" width="320" /></a></div><br />
<br />
Source Code:<br />
<br />
<b>Java Script:</b><br />
<br />
<br />
function Submit1_onclick() {<br />
<br />
var t1,t2,t3,t4,t5;<br />
t1 = document.getElementById("TextBox1"); <br />
if(t1.value == "")<br />
{<br />
alert("enter the Name ");<br />
document.getElementById("TextBox1").focus();<br />
//t1.value=" " ; <br />
return false;<br />
}<br />
<br />
t2 = document.getElementById("TextBox2"); <br />
if(t2.value == "")<br />
{<br />
alert("enter the Reg Number");<br />
document.getElementById("TextBox2").focus();<br />
return false;<br />
<br />
}<br />
<br />
t3 = document.getElementById("TextBox3"); <br />
if(t3.value == "")<br />
{<br />
alert("enter the Pass Word");<br />
document.getElementById("TextBox3").focus();<br />
return false;<br />
<br />
}<br />
<br />
t4 = document.getElementById("TextBox4"); <br />
if(t4.value == "" )<br />
{<br />
alert("enter the Confirm Pass Word");<br />
document.getElementById("TextBox4").focus();<br />
return false;<br />
<br />
}<br />
<br />
if( t3.value != t4.value)<br />
{<br />
alert (" Pass Word Mismatch ");<br />
return false;<br />
}<br />
<br />
t5 = document.getElementById("TextBox5"); <br />
if(t5.value == "")<br />
{<br />
alert("enter the e-mail");<br />
return false;<br />
}<br />
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;<br />
<br />
var emailid = document.getElementById("TextBox5").value;<br />
<br />
var matchArray = emailid.match(emailPat);<br />
<br />
if (matchArray == null)<br />
{<br />
alert("Your email address seems incorrect. Please try again.");<br />
<br />
document.getElementById("TextBox5").focus();<br />
<br />
return false;<br />
}<br />
<br />
<br />
t6 = document.getElementById("TextBox6"); <br />
if(t6.value == "")<br />
{<br />
alert("enter the Date of Birth");<br />
return false;<br />
<br />
}<br />
//var dateform =/(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/; //mm/dd/yyyy<br />
alert("Please click the Submit Button"); <br />
return true;<br />
}<br />
<br />
<br />
<br />
<b>The Default.aspx.cs file is</b><br />
<br />
using System;<br />
using System.Configuration;<br />
using System.Data;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Xml.Linq;<br />
using System.Data.SqlClient;<br />
<br />
public partial class _Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
// if(!(Page.IsPostBack))<br />
// only executes for the first time of the page load event.. initially alone<br />
//Button1.Attributes.Add("onclick", "Submit1_onclick();"); <br />
<br />
}<br />
<br />
public string name1, password1, email1, dob1;<br />
public int regno1;<br />
SqlCommand cmd;<br />
<br />
//submit<br />
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
<br />
string constr, query;<br />
constr = "Data Source=6;Initial Catalog=employee123;User ID=sa;Password=123";<br />
SqlConnection conn = new SqlConnection(constr);<br />
try<br />
{<br />
<br />
/*query = "Insert into regform values(@name,@regno,@password,@email,@DOB)";<br />
cmd = new SqlCommand(query, conn);<br />
cmd.Parameters.AddWithValue("@name",TextBox1.Text);<br />
cmd.Parameters.AddWithValue("@regno",TextBox2.Text);<br />
cmd.Parameters.AddWithValue("@password",TextBox3.Text);<br />
cmd.Parameters.AddWithValue("@email", TextBox5.Text);<br />
cmd.Parameters.AddWithValue("@DOB", TextBox6.Text);<br />
conn.Open();<br />
cmd.ExecuteNonQuery();<br />
conn.Close();<br />
Response.Write("the value updated successfully");*/<br />
<br />
cmd = new SqlCommand("regforms_sp", conn);<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox1.Text;<br />
cmd.Parameters.Add("@regno", SqlDbType.VarChar).Value = TextBox2.Text;<br />
cmd.Parameters.Add("@passwords", SqlDbType.VarChar).Value = TextBox3.Text;<br />
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = TextBox5.Text;<br />
cmd.Parameters.Add("@DOB", SqlDbType.VarChar).Value = TextBox6.Text;<br />
conn.Open();<br />
int rows = cmd.ExecuteNonQuery();<br />
conn.Close(); <br />
<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
Response.Write(ex);<br />
}<br />
}<br />
//display<br />
protected void Button2_Click(object sender, EventArgs e)<br />
{<br />
string constr;<br />
<br />
constr = "Data Source=6;Initial Catalog=employee123;User ID=sa;Password=123";<br />
<br />
SqlConnection conn = new SqlConnection(constr);<br />
try<br />
{ <br />
<br />
string sql123 = "select * from regforms ";<br />
SqlDataAdapter da = new SqlDataAdapter(sql123,conn); <br />
DataSet ds = new DataSet(); <br />
da.Fill(ds);<br />
int y = 0;<br />
for (int x=1; x < ds.Tables[0].Rows.Count;y++)<br />
{<br />
Response.Write(ds.Tables[0].Rows[x].ItemArray[y].ToString());<br />
if (y == 4)<br />
break;<br />
}<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
Response.Write(ex);<br />
<br />
}<br />
<br />
}<br />
protected void TextBox6_TextChanged(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
}Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com0tag:blogger.com,1999:blog-8442312247778848319.post-22681578114967999702010-05-11T11:15:00.003+05:302010-10-14T00:10:35.206+05:30XML Manipulation in C# .NETXML Insert, Update ,Delete Example<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_dRN5PKJdoW4/S-jt_pLQluI/AAAAAAAAAAU/r_-xrFs6APM/s1600/xml.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/_dRN5PKJdoW4/S-jt_pLQluI/AAAAAAAAAAU/r_-xrFs6APM/s320/xml.bmp" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>Source Code:</b></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Collections.Generic;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.ComponentModel;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Data;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Drawing;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Linq;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Text;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Windows.Forms;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">using System.Xml;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">namespace xmlupdate</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public partial class Form1 : Form</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public static int ii =0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public static int i = 0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public static int j = 0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public static int x = 0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public static int flag=0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">string[] str1 = new string[20];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlTextWriter xwr;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlDocument doc = new XmlDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlNodeList n1;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">public Form1()</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">InitializeComponent();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void Form1_Load(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr = new XmlTextWriter("sample123.xml", null);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteStartDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteStartElement("TasksMain");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.Formatting = Formatting.Indented;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteComment("This is comment Line");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//create</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button1_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == ""))</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">label4.Text = "please enter the values";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">else</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteStartElement("Tasks");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteElementString("name", textBox1.Text);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteElementString("age", textBox2.Text);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteElementString("sex", textBox3.Text);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteEndElement();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">label4.Text = "Record created success fully";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox1.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox2.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox3.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void Form1_FormClosed(object sender, FormClosedEventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if (flag != 1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteEndElement();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteEndDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.Close();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//display</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button2_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//xwr.WriteEndElement();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//xwr.WriteEndDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//xwr.Close();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">flag = 1;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">doc.Load("sample123.xml");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlNodeReader reader = new XmlNodeReader(doc);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">while (reader.Read())</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">switch (reader.NodeType)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">case XmlNodeType.Text:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">str1[ii] = reader.Value;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">ii++;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">break;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">for (; i < 3; i++)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox1.Text = str1[0];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox2.Text = str1[1];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox3.Text = str1[2];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">button2.Enabled = false;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">reader.Close();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//display next</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button4_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">try</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox1.Text = str1[x];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox2.Text = str1[x + 1];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox3.Text = str1[x + 2];</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">x += 3;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">catch (Exception e1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">MessageBox.Show("" + e1);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">button2.Enabled = false;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//append</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button3_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">// XmlDocument doc1 = new XmlDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//doc1.Load("ooty1.xml");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == ""))</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">label4.Text = "please enter the values";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//doc.Load("sample123.xml");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//XmlElement MainTasks = doc.CreateElement("TasksMain22");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlElement newTasks = doc.CreateElement("Tasks");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlElement newname = doc.CreateElement("name");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newname.InnerText = textBox1.Text;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlElement newage = doc.CreateElement("age");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newage.InnerText = textBox2.Text;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlElement newgen = doc.CreateElement("sex");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newgen.InnerText = textBox3.Text;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newTasks.AppendChild(newname);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newTasks.AppendChild(newage);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">newTasks.AppendChild(newgen);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">doc.DocumentElement.AppendChild(newTasks);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">doc.Save("sample123.xml");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">label4.Text = "Record Updated Successfully";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">button9.PerformClick();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//MainTasks.AppendChild(newTasks);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//delete </span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button5_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">string match;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">match = textBox4.Text;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlNodeList nodeList = doc.SelectNodes("TasksMain");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">n1 = doc.GetElementsByTagName("Tasks");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">int flaggy = 0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">foreach (XmlNode node in n1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if ( match == node.SelectSingleNode("name").InnerText)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">flaggy = 1;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">doc.DocumentElement.RemoveChild(node);</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">doc.Save("sample123.xml");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">MessageBox.Show("the node deleted");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//textBox1.Text = node.SelectSingleNode("name").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//textBox2.Text = node.SelectSingleNode("age").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//textBox3.Text = node.SelectSingleNode("sex").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if (flaggy == 1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">break;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//writing finished</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button6_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteEndElement();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.WriteEndDocument();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">xwr.Close();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">button6.Enabled = false;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">button1.Enabled = false;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//clear</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button9_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox1.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox2.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox3.Text = "";</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">//find..</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button7_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">XmlNodeList nodeList = doc.SelectNodes("TasksMain");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">n1 = doc.GetElementsByTagName("Tasks");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">int flaggy = 0;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">foreach (XmlNode node in n1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if(textBox4.Text == node.SelectSingleNode("name").InnerText)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">flaggy = 1;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox1.Text = node.SelectSingleNode("name").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox2.Text = node.SelectSingleNode("age").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">textBox3.Text = node.SelectSingleNode("sex").InnerText;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if (flaggy == 1)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">break;</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">if(flaggy == 0)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">MessageBox.Show("Sorry Record not Found");</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">private void button8_Click(object sender, EventArgs e)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">{</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">this.Close();</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">}</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b><br />
</b></span>Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com0tag:blogger.com,1999:blog-8442312247778848319.post-63031867896271742322010-05-11T11:05:00.001+05:302010-10-14T00:11:41.217+05:30Database ConnectivityThe following example shows how to connect the C# .net form with the SQL Server 2005<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_dRN5PKJdoW4/S-jr5A0XwII/AAAAAAAAAAM/rx7DXfCLeoo/s1600/s.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/_dRN5PKJdoW4/S-jr5A0XwII/AAAAAAAAAAM/rx7DXfCLeoo/s320/s.bmp" /></a></div><br />
<br />
The Source code is given below............................<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Data.SqlClient;<br />
using Microsoft.VisualBasic;<br />
<br />
<br />
namespace DBConnect<br />
{<br />
public partial class Form1 : Form<br />
{<br />
SqlConnection con;<br />
SqlDataAdapter da;<br />
SqlCommandBuilder cb;<br />
DataSet ds;<br />
int rno = 0;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void ShowData()<br />
{<br />
textBox1.Text = ds.Tables[0].Rows[rno][0].ToString();<br />
textBox2.Text = ds.Tables[0].Rows[rno][1].ToString();<br />
textBox3.Text = ds.Tables[0].Rows[rno][2].ToString();<br />
textBox4.Text = ds.Tables[0].Rows[rno][3].ToString();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
con = new SqlConnection("user ID=sa; Password=sasa; Database=employee123");<br />
<br />
da = new SqlDataAdapter("Select * From concern", con);<br />
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;<br />
ds = new DataSet();<br />
da.Fill(ds, "concern");<br />
ShowData();<br />
<br />
}<br />
//First<br />
private void button3_Click_1(object sender, EventArgs e)<br />
{<br />
rno = 0;<br />
ShowData();<br />
}<br />
//insert<br />
private void button6_Click_1(object sender, EventArgs e)<br />
{<br />
DataRow dr = ds.Tables[0].NewRow();<br />
dr[0] = textBox1.Text;<br />
dr[1] = textBox2.Text;<br />
dr[2] = textBox3.Text;<br />
dr[3] = textBox4.Text;<br />
ds.Tables[0].Rows.Add(dr);<br />
MessageBox.Show("Inserted");<br />
button3.PerformClick();<br />
<br />
}<br />
//update<br />
private void button7_Click_1(object sender, EventArgs e)<br />
{<br />
ds.Tables[0].Rows[rno][0] = textBox1.Text;<br />
ds.Tables[0].Rows[rno][1] = textBox2.Text;<br />
ds.Tables[0].Rows[rno][2] = textBox3.Text;<br />
ds.Tables[0].Rows[rno][3] = textBox4.Text;<br />
MessageBox.Show("Updated");<br />
<br />
}<br />
//delete<br />
private void button8_Click_1(object sender, EventArgs e)<br />
{<br />
ds.Tables[0].Rows[rno].Delete();<br />
MessageBox.Show("Deleted");<br />
button3.PerformClick();<br />
<br />
}<br />
//Save<br />
private void button9_Click_1(object sender, EventArgs e)<br />
{<br />
cb = new SqlCommandBuilder(da);<br />
da.Update(ds, "concern");<br />
MessageBox.Show("Data Saved to DB");<br />
}<br />
//Find<br />
private void button10_Click_1(object sender, EventArgs e)<br />
{<br />
/* int sno = int.Parse(Interaction .InputBox("Enter Employee No", "Question Message", "", 100, 100));<br />
DataRow dr = ds.Tables[0].Rows.Find(sno);<br />
textBox1.Text = dr[0].ToString();<br />
textBox2.Text = dr[1].ToString();<br />
textBox3.Text = dr[2].ToString();<br />
textBox4.Text = dr[3].ToString();*/<br />
<br />
}<br />
<br />
<br />
//next<br />
private void button1_Click_1(object sender, EventArgs e)<br />
{<br />
if (rno < ds.Tables[0].Rows.Count - 1)<br />
{<br />
rno++;<br />
ShowData();<br />
}<br />
else<br />
MessageBox.Show("Last Record");<br />
}<br />
//Previous<br />
private void button2_Click_1(object sender, EventArgs e)<br />
{<br />
if (rno > 0)<br />
{<br />
rno -= 1;<br />
ShowData();<br />
}<br />
else<br />
MessageBox.Show("First Record");<br />
}<br />
//last<br />
private void button4_Click_1(object sender, EventArgs e)<br />
{<br />
rno = ds.Tables[0].Rows.Count - 1;<br />
ShowData();<br />
}<br />
<br />
private void button5_Click_1(object sender, EventArgs e)<br />
{<br />
textBox1.Clear();<br />
textBox2.Clear();<br />
textBox3.Clear();<br />
textBox4.Clear();<br />
}<br />
}<br />
}<br />
<div><br />
</div>Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com1tag:blogger.com,1999:blog-8442312247778848319.post-17107906978082502472010-04-26T10:36:00.000+05:302010-10-14T00:09:36.668+05:30Custom Event Handling in C Sharp .NET with Delegates<div><span class="Apple-style-span" style="font-family:'times new roman';">This is easy example for Custom Events Handling.</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">1.Create a form with two label and two text box and two button with the text "Add" and "Clear"</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Collections.Generic;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.ComponentModel;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Data;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Drawing;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Linq;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Text;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">using System.Windows.Forms;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">namespace CustomEvents2</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">{</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public delegate void MyCustomEvents(string target);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public partial class Form1 : Form</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public Form1()</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> InitializeComponent();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public int txt_val1, txt_val2;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public int aval, bval;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> TextBox txt1 = new TextBox();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> TextBox txt2 = new TextBox();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> TextBox txt3 = new TextBox();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> Button btn = new Button();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public event MyCustomEvents MyEvents;</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> private void Form1_Load(object sender, EventArgs e)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> Label lbl1 = new Label();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl1.Text = "Enter A value";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl1.Location = new Point(0, 100);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt1.Location = new Point(100, 100);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt1.Text = "";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> Label lbl2 = new Label();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl2.Text = "Enter B value";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl2.Location = new Point(0, 150);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt2.Location = new Point(100, 150);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt2.Text = "";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> Label lbl3 = new Label();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl3.Text = "A + B is";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> lbl3.Location = new Point(0, 170);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt3.Location = new Point(100, 175);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> btn.Location = new Point(100, 225);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> btn.Text = "add";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(lbl1);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(txt1);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(lbl2);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(txt2);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(lbl3);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.Controls.Add(txt3);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public class MyButttonEvent : Button </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> //constructors</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public MyButttonEvent()</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> // this.Click += new MyCustomEvents(this,m1.Addition);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> } </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> private void button1_Click(object sender, EventArgs e)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> aval = Convert.ToInt32(txt1.Text);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> bval = Convert.ToInt32(txt2.Text);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.MyEvents += new MyCustomEvents(Addition);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> if (aval != 0 && bval != 0)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> if (this.MyEvents != null)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> this.MyEvents("add");</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> public void Addition(string t)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt_val1 = Convert.ToInt32(txt1.Text);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt_val2 = Convert.ToInt32(txt2.Text);</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt3.Text = (txt_val1 + txt_val2).ToString();</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> private void button2_Click(object sender, EventArgs e)</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> {</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt1.Text = "";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt2.Text = "";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> txt3.Text = "";</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> }</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> } </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">}</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"> </span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><br /></div>Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com0tag:blogger.com,1999:blog-8442312247778848319.post-41726494853479501372010-04-26T10:25:00.002+05:302010-10-14T00:09:36.668+05:30Custom Event Handling in C Sharp .NET<div>Hi, </div><div><br />
</div><div>This is the good example for Event handling mechanism with system events.</div><div><br />
</div><div>using System;</div><div>using System.Collections.Generic;</div><div>using System.ComponentModel;</div><div>using System.Data;</div><div>using System.Drawing;</div><div>using System.Linq;</div><div>using System.Text;</div><div>using System.Windows.Forms;</div><div><br />
</div><div>namespace eventmgmt</div><div>{</div><div>public delegate void NameButtonClicked(object sender, EventArgs e);</div><div><br />
</div><div>public partial class Form1 : Form</div><div>{</div><div>public Form1()</div><div>{</div><div>InitializeComponent();</div><div>}</div><div></div><div>int txt_val1, txt_val2; </div><div>TextBox txt1 = new TextBox();</div><div>TextBox txt2 = new TextBox();</div><div>TextBox txt3 = new TextBox();</div><div>Button btn = new Button();</div><div>private void Form1_Load(object sender, EventArgs e)</div><div>{</div><div></div><div>Label lbl1 = new Label();</div><div><br />
</div><div>lbl1.Text = "Enter A value";</div><div>lbl1.Location = new Point(0, 100);</div><div><br />
</div><div>txt1.Location = new Point(100, 100);</div><div>txt1.Text = "";</div><div><br />
</div><div>Label lbl2 = new Label();</div><div>lbl2.Text = "Enter B value";</div><div>lbl2.Location = new Point(0, 150);</div><div><br />
</div><div>txt2.Location = new Point(100, 150);</div><div>txt2.Text = "";</div><div><br />
</div><div>Label lbl3 = new Label();</div><div>lbl3.Text = "A + B is";</div><div>lbl3.Location = new Point(0, 170);</div><div><br />
</div><div>txt3.Location = new Point(100, 175);</div><div><br />
</div><div>btn.Location = new Point(100, 225);</div><div>btn.Text = "add";</div><div><br />
</div><div>this.Controls.Add(lbl1);</div><div>this.Controls.Add(txt1);</div><div>this.Controls.Add(lbl2);</div><div>this.Controls.Add(txt2);</div><div>this.Controls.Add(lbl3);</div><div>this.Controls.Add(txt3);</div><div>this.Controls.Add(btn);</div><div><br />
</div><div>btn.Click += new System.EventHandler(NameButtonClicked);</div><div><br />
</div><div>}</div><div>public void NameButtonClicked(object sender, EventArgs e)</div><div>{</div><div>txt_val1 = Convert.ToInt32(txt1.Text);</div><div><br />
</div><div>txt_val2 = Convert.ToInt32(txt2.Text);</div><div>txt3.Text = (txt_val1 + txt_val2).ToString(); </div><div></div><div>}</div><div><br />
</div><div>}</div><div>}</div><div><br />
</div>Ayyappanhttp://www.blogger.com/profile/00790252832198108588noreply@blogger.com0