0% found this document useful (0 votes)
15 views

For Managment

This document contains the code for a web form application that performs CRUD (create, read, update, delete) operations on an item master database table. It defines event handler methods for buttons to save, edit, delete, search, and clear data. On page load, it opens a SQL connection. The save, edit, and delete buttons execute SQL commands with parameters from textboxes to insert, update, or delete a database record. The search button populates the textboxes from a record found by primary key.

Uploaded by

Nandini Kathane
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

For Managment

This document contains the code for a web form application that performs CRUD (create, read, update, delete) operations on an item master database table. It defines event handler methods for buttons to save, edit, delete, search, and clear data. On page load, it opens a SQL connection. The save, edit, and delete buttons execute SQL commands with parameters from textboxes to insert, update, or delete a database record. The search button populates the textboxes from a record found by primary key.

Uploaded by

Nandini Kathane
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Configuration;
using System.Data;
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;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page


{
SqlConnection objcon = new SqlConnection();
SqlCommand objcmd = new SqlCommand();
SqlDataReader objdr;
SqlDataAdapter objadpt = new SqlDataAdapter();

protected void Page_Load(object sender, EventArgs e)


{
objcon = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=D:\sachin\Item_Info.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True");
objcon.Open();

}
protected void btnSave_Click(object sender, EventArgs e)
{
// objcmd = new SqlCommand("Select * form ITEM_MAST",objcon);
string str =" insert into ITEM_MAST
values("+txtitemcode.Text+",'"+txtitemname.Text+"','"+txtitemdesc.Text+"',"+tx
titemsellprice.Text+")" ;
objcmd = new SqlCommand(str, objcon);
int i = objcmd.ExecuteNonQuery();
if (i != 0)
{
Label5.Text = "Record Inserted";
}
else
{
Label5.Text = "Record not Inserted";
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
string str = " update ITEM_MAST set Item_Name='" + txtitemname.Text +
"',Item_Desc='" + txtitemdesc.Text + "',Item_sellingprice='" +
txtitemsellprice.Text + "'where Item_code="+txtitemcode.Text+"";
objcmd = new SqlCommand(str, objcon);
int i = objcmd.ExecuteNonQuery();
if (i != 0)
{
Label5.Text = "Record Updated";
}
else
{
Label5.Text = "Record not Insertrd";
}
}
protected void btndelete_Click(object sender, EventArgs e)
{
string str = "Delete from ITEM_MAST where
Item_code="+txtitemcode.Text+"";
objcmd = new SqlCommand(str,objcon);
int i=objcmd.ExecuteNonQuery();
if (i != 0)
{
Label5.Text = "Record Deleted";
Clear();
}
else
{
Label5.Text = "Record Allready Deleted";
}

}
protected void txtitemcode_TextChanged(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
objcmd = new SqlCommand("Select * from ITEM_MAST where Item_code=" +
txtitemcode.Text + "", objcon);
// objcmd.ExecuteReader();
objdr = objcmd.ExecuteReader();
// int i = objdr;

while (objdr.Read())
{
if (objdr.HasRows)
{

txtitemcode.Text = objdr[0].ToString();
txtitemname.Text = objdr[1].ToString();
txtitemdesc.Text = objdr[2].ToString();
txtitemsellprice.Text = objdr[3].ToString();

}
else
{
Label5.Text = "Record Not Avalible ";
}

}
objdr.Close();
}
protected void btnclear_Click(object sender, EventArgs e)
{
Clear();
}
public void Clear()
{
txtitemcode.Text = "";
txtitemname.Text = "";
txtitemdesc.Text = "";
txtitemsellprice.Text = "";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
}

You might also like