Maruthupandi (25.08.2022)
Maruthupandi (25.08.2022)
Maruthupandi (25.08.2022)
cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace CRUDWebAppplication
{
public partial class CRUD : System.Web.UI.Page
{
DataAccessObject dao = new DataAccessObject();
protected void Page_Load(object sender, EventArgs e)
{
DataAccessObject.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace CRUDWebAppplication
{
public class DataAccessObject
{
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
SqlDataAdapter adapter;
DataTable table;
public DataAccessObject()
{
connection = new
SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ToString());
connection.Open();
command.Parameters.AddWithValue("@empName", name);
command.Parameters.AddWithValue("@empPhNo", mobile);
command.Parameters.AddWithValue("@empEmail", email);
command.Parameters.AddWithValue("@monthName", gender);
command.Parameters.AddWithValue("@empDept", dept);
command.Parameters.AddWithValue("@empDesign", design);
int y = command.ExecuteNonQuery();
return y;
}
connection.Close();
connection.Open();
command = new SqlCommand("Delete From Employee Where MobNumber=
@mobile", connection);
command.Parameters.AddWithValue("@mobile", mobile);
int x = command.ExecuteNonQuery();
return x;
}
public DataTable viewDetails()
{
connection.Close();
connection.Open();
adapter = new SqlDataAdapter("select * from Employee", connection);
table = new DataTable();
adapter.Fill(table);
return table;
}
public string[] findDetail(string mobile)
{
connection.Close();
connection.Open();
command = new SqlCommand("select * from Employee Where
MobNumber=@mobile", connection);
command.Parameters.AddWithValue("@mobile", mobile);
reader = command.ExecuteReader();
if (reader.Read())
{
data[0] = reader[0].ToString();
data[1] = reader[2].ToString();
data[2] = reader[4].ToString();
data[3] = reader[5].ToString();
}
else
{
data = new string[0];
}
return data;
}
public int upadateDetails(string name, string mobile, string email, string
dept, string design)
{
connection.Close();
connection.Open();
command.Parameters.AddWithValue("@employeename", name);
command.Parameters.AddWithValue("@email", email);
command.Parameters.AddWithValue("@mobile", mobile);
command.Parameters.AddWithValue("@department", dept);
command.Parameters.AddWithValue("@designation", design);
int y = command.ExecuteNonQuery();
return y;
}
}
web.config
<configuration>
<connectionStrings>
<add name="dbConnection" connectionString="Data Source=(localdb)\
MSSQLLocalDB;database=sampldb;Integrated security=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>