ASPX code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Name | ||
Mobile No. | ||
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();
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Sandeep ShekhawatPosted Jun 28, 2011, 8:51 AM
http://www.c-sharpcorner.com/Forums/Thread/126081/n-tier-application-using-C-Sharp.aspx
But u simply use sqlcommand and sql dataadpater for store procedure.
for update use like this
and for select use like This:
Jaganathan BantheswaranPosted Jun 28, 2011, 8:41 AM
Read this http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx