CS code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data source=TECHID\SQLEXPRESS;initial catalog=test_abdhesh;integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
}
void clear()
{
txt_mobileNo.Text = "";
txt_name.Text = "";
}
protected void btn_Add_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into phone_book values('" + txt_name.Text.ToString() + "','" + txt_mobileNo.Text.ToString() + "')", con);
cmd.ExecuteNonQuery();
clear();
}
catch (Exception ex)
{
Response.Write("This Mobile No. alreay Exist");
}
finally
{
con.Close();
}
}
protected void btn_View_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select P_name, P_no from phone_book where P_no='" + txt_mobileNo.Text.ToString() + "'", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
txt_name.Text = dr[0].ToString();
txt_mobileNo.Text = dr[1].ToString();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
protected void btn_update_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("update phone_book set P_name='" + txt_name.Text.ToString() + "' where P_no='" + txt_mobileNo.Text.ToString() + "'", con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
}