protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
//cmd = new SqlCommand("insert into unitmaster(unitname,description) values(@name,@des)", con);
//cmd.Parameters.AddWithValue("@name", TextBox1.Text.Trim());
//cmd.Parameters.AddWithValue("@des", TextBox2.Text.Trim());
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
//TextBox1.Text = string.Empty;
//TextBox2.Text = string.Empty;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@unitname", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@description", TextBox2.Text.Trim());
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Insert Successful')</script>");
}
showdata();
}
else
{
Response.Write("Please fill Blood name");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//SqlCommand cmd = new SqlCommand("delete from unitmaster where id=@id", con);
//cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value));
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Delete Successful')</script>");
}
showdata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//SqlCommand cmd = new SqlCommand("update unitmaster set unitname=@name,description=@description where id=@id", con);
//cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
//cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("ename"))).Text;
//cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("edescription"))).Text;
////cmd.Parameters.Add("@status", SqlDbType.NVarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("estatus"))).Text;
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
//GridView1.EditIndex = -1;
//showdata();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value));
cmd.Parameters.AddWithValue("@unitname",((TextBox)(GridView1.Rows[e.RowIndex].FindControl("ename"))).Text);
cmd.Parameters.AddWithValue("@description",((TextBox)(GridView1.Rows[e.RowIndex].FindControl("edescription"))).Text);
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Update Successful')</script>");
}
GridView1.EditIndex = -1;
showdata();
}
protected void showdata()
{
//DISCONNECTED MODE
//SqlDataAdapter da =new SqlDataAdapter();
//da.SelectCommand.CommandText = "select_unitmaster";
//da.SelectCommand.CommandType = CommandType.StoredProcedure;
//dt=new DataTable();
//da.Fill(dt);
//GridView1.DataSource=dt;
//GridView1.DataBind();
//CONNECTED MODE
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
}
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[insert_unitmaster] Script Date: 08/02/2013 17:13:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insert_unitmaster]
(
@unitname varchar(50),
@description nvarchar(300)
)
as
begin
insert into unitmaster(unitname,description)
values(@unitname,@description)
end
GO
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[update_unitmaster] Script Date: 08/02/2013 17:14:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[update_unitmaster]
(
@id int,
@unitname varchar(50),
@description nvarchar(300)
)
as
begin
update unitmaster set unitname=@unitname,description=@description where id=@id
end
GO
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[delete_unitmaster] Script Date: 08/02/2013 17:14:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[delete_unitmaster]
(
@id int
)
as
begin
delete from unitmaster where id=@id
end
GO
{
if (TextBox1.Text != "")
{
//cmd = new SqlCommand("insert into unitmaster(unitname,description) values(@name,@des)", con);
//cmd.Parameters.AddWithValue("@name", TextBox1.Text.Trim());
//cmd.Parameters.AddWithValue("@des", TextBox2.Text.Trim());
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
//TextBox1.Text = string.Empty;
//TextBox2.Text = string.Empty;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@unitname", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@description", TextBox2.Text.Trim());
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Insert Successful')</script>");
}
showdata();
}
else
{
Response.Write("Please fill Blood name");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//SqlCommand cmd = new SqlCommand("delete from unitmaster where id=@id", con);
//cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value));
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Delete Successful')</script>");
}
showdata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//SqlCommand cmd = new SqlCommand("update unitmaster set unitname=@name,description=@description where id=@id", con);
//cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
//cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("ename"))).Text;
//cmd.Parameters.Add("@description", SqlDbType.VarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("edescription"))).Text;
////cmd.Parameters.Add("@status", SqlDbType.NVarChar).Value = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("estatus"))).Text;
//con.Open();
//cmd.ExecuteNonQuery();
//con.Close();
//GridView1.EditIndex = -1;
//showdata();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value));
cmd.Parameters.AddWithValue("@unitname",((TextBox)(GridView1.Rows[e.RowIndex].FindControl("ename"))).Text);
cmd.Parameters.AddWithValue("@description",((TextBox)(GridView1.Rows[e.RowIndex].FindControl("edescription"))).Text);
con.Open();
int x = cmd.ExecuteNonQuery();
con.Close();
if (x == 0)
{
}
if (x > 0)
{
Response.Write("<script LANGUAGE='JavaScript' >alert('Update Successful')</script>");
}
GridView1.EditIndex = -1;
showdata();
}
protected void showdata()
{
//DISCONNECTED MODE
//SqlDataAdapter da =new SqlDataAdapter();
//da.SelectCommand.CommandText = "select_unitmaster";
//da.SelectCommand.CommandType = CommandType.StoredProcedure;
//dt=new DataTable();
//da.Fill(dt);
//GridView1.DataSource=dt;
//GridView1.DataBind();
//CONNECTED MODE
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select_unitmaster";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
}
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[insert_unitmaster] Script Date: 08/02/2013 17:13:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[insert_unitmaster]
(
@unitname varchar(50),
@description nvarchar(300)
)
as
begin
insert into unitmaster(unitname,description)
values(@unitname,@description)
end
GO
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[update_unitmaster] Script Date: 08/02/2013 17:14:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[update_unitmaster]
(
@id int,
@unitname varchar(50),
@description nvarchar(300)
)
as
begin
update unitmaster set unitname=@unitname,description=@description where id=@id
end
GO
USE [hms]
GO
/****** Object: StoredProcedure [dbo].[delete_unitmaster] Script Date: 08/02/2013 17:14:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[delete_unitmaster]
(
@id int
)
as
begin
delete from unitmaster where id=@id
end
GO
No comments:
Post a Comment