creating and throwing a custom exception

class MyException : ApplicationException
{
public void Myexption()
{
Console.Write(“an exception occured”);
}
public void mydivideexception()
{
Console.Write(“exception occured when divide byzero”);
}
public void hello()
{
Console.WriteLine(“hello”);
}
}
class Class1
{
public static void Main()
{
int d, div, res;
div = Convert.ToInt32(Console.ReadLine());
d = Int32.Parse(Console.ReadLine());
try
{
if (div == 0)
{
throw new MyException();
}
else
{
res = d / div;
Console.WriteLine(“Result:{0}”, res);
}
}
catch (MyException e)
{
e.hello();
}

}

}

Standard

performing addition of a list of column values

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”false” Height=”176px” Width=”304px” ShowFooter=”true” OnRowDataBound=”GridView1_RowDataBound”>
<Columns>
<asp:TemplateField HeaderText=”empid”>
<ItemTemplate>
<asp:Label runat=”server” ID=”lblid” Text='<%#Eval(“empid”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID=”Label1″ runat=”server” Text=”Total Is:”></asp:Label>
<asp:Label ID=”lbltotal” runat=”server” ></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText=”ename” DataField=”ename”
/>
</Columns>
</asp:GridView>

 

 

Code Behind Code:

public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(“Data Source=SPARSH238\\SQLSERVER2008R2;Initial Catalog=kalyani;User ID=sa;Password=sparsh”);
int tot;
protected void Page_Load(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter(“select * from emp3”, con);
DataSet ds = new DataSet();
da.Fill(ds, “x”);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
Label l = (Label)e.Row.FindControl(“lblid”);
tot = tot + Convert.ToInt32(l.Text);
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label ltot = (Label)e.Row.FindControl(“lbltotal”);
ltot.Text = tot.ToString();

}

}
}

Standard

creating datatable

DataTable dt = new DataTable();
dt.Columns.Add(“eid”, typeof(string));
dt.Columns.Add(“ename”, typeof(string));
dt.Columns.Add(“desig”, typeof(string));
dt.Columns.Add(“salary”, typeof(string));

dt.Rows.Add(“101”, “sai”, “pl”, “100000”);
dt.Rows.Add(“102”, “sai”, “pl”, “200000”);
dt.Rows.Add(“103”, “sai”, “pl”, “300000”);
dt.Rows.Add(“104”, “sai”, “pl”, “400000”);

return dt

Standard