how to calculate area & save the data in database
Enter Width
Enter Heigh
Area is
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial
class AreaRectangle
: System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
protected void Button1_Click(object
sender, EventArgs e)
{
float
fWidth;
float
fHeight;
float
fArea;
fWidth = Convert.ToInt64(txtWidth.Text);
fHeight = Convert.ToInt64(txtHeight.Text);
fArea = (fWidth * fHeight);
txtArea.Text = Convert.ToString(fArea);
}
protected void Button2_Click(object
sender, EventArgs e)
{
string
connectionString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
string
insertSql = "INSERT INTO
AreaOfRect(rwidth,rheight,rarea) VALUES(@rwidth, @rheight,@rarea)";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand
myCommand = new SqlCommand(insertSql,
myConnection);
myCommand.Parameters.AddWithValue("@rwidth", txtWidth.Text);
myCommand.Parameters.AddWithValue("@rheight", txtHeight.Text);
myCommand.Parameters.AddWithValue("@rarea", txtArea.Text);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
//
"Reset" the Subject and Body TextBoxes
txtWidth.Text = string.Empty;
txtHeight.Text = string.Empty;
txtArea.Text = string.Empty;
}
}
Contact : +91-9040573923, +91-7008182025
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations