The Simplest CRUD Operations for Lookup Tables in ASP.NET - Points to note
(Page 7 of 7 )
Even though I didn't talk about "delete" in the above sections, it is worth mentioning. Actually, deleting a record is as simple as including the following:
PrivateSub Delete(ByVal DeptID As String)
db.SQLExecute("delete from dept where deptno=" & DeptID)
BindGrid()
End Sub
I included the following JavaScript to add confirmation for the delete operation.
<script language="javascript">
function getConfirm()
{
if (confirm("Are you sure to delete record?")
==true)
return true;
else
return false;
}
</script>
To activate the above script, I included the following:
PrivateSub DataGrid1_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Handles DataGrid1.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
e.Item.Cells(1).Attributes.Add("onclick", "return
getConfirm();")
End Select
End Sub
To work with my sample, I simply created a table "dept" using the following command:
CREATE TABLE [dbo].[dept] (
[deptno] [int] NOT NULL ,
[dname] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[loc] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
) ON [PRIMARY]
Try to insert some rows into the above table using following commands:
insert into dept values (10,'Accounting','Dallas')
insert into dept values (20,'Production','Washington')
The entire code for this article is freely available in the form of a zip file. That downloadable solution was developed using Microsoft Visual Studio 2003 Enterprise Architect together with SQL Server 2000 on Microsoft Windows 2003 Standard Edition. I didn't really test it in any other version.
Any doubts, bugs, errors, suggestions, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |