Click here to Skip to main content
15,896,441 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi, please any one help me the logic of update button and delete button logic, here i am using gridview with sqlserver, and my table name is TESTING and my coloms is empid,empno, empadress.

help me please
Posted
Updated 31-Mar-14 18:55pm
v2

Hey Buddy,

The Update event:

At first, you need to create the OnRowUpdating Event from the event window of the GridView:

VB
Protected Sub DataGridView_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
    Dim ID As Label = TryCast(DataGridView.Rows(e.RowIndex).FindControl("LblStuID"), Label)
    Dim Name As TextBox = TryCast(DataGridView.Rows(e.RowIndex).FindControl("TxtEditStuName"), TextBox)
    Dim Gender As DropDownList = TryCast(DataGridView.Rows(e.RowIndex).FindControl("DDLEditStuGender"), DropDownList)
    Dim Grad As TextBox = TryCast(DataGridView.Rows(e.RowIndex).FindControl("TxtEditStuGraduation"), TextBox)
    Dim PostGrad As TextBox = TryCast(DataGridView.Rows(e.RowIndex).FindControl("TxtEditStuPostGraduation"), TextBox)
    Dim Mobile As TextBox = TryCast(DataGridView.Rows(e.RowIndex).FindControl("TxtEditStuMobileNo"), TextBox)
    Dim Email As TextBox = TryCast(DataGridView.Rows(e.RowIndex).FindControl("TxtEditStuEmailID"), TextBox)

    Dim Message As String = obj.Updata_Data(ID, Name, Gender.SelectedItem, Grad, PostGrad, Mobile, _
        Email)
    Fill_Grid()
    Literal1.Text = Message
End Sub


Update_Data definition is:


SQL
Public Function Updata_Data(ID As Label, Name As TextBox, listItem As ListItem, Grad As TextBox, PostGrad As TextBox, Mobile As TextBox, _
    Email As TextBox) As String
    cmd = New SqlCommand("Update Tbl_Student set Stu_Name='" & Convert.ToString(Name.Text) & "', Stu_Gender='" & Convert.ToString(listItem.Text) & "', Stu_Graduation='" & Convert.ToString(Grad.Text) & "', Stu_PostGraduation='" & Convert.ToString(PostGrad.Text) & "', Stu_MobileNo=" & Convert.ToString(Mobile.Text) & ", Stu_EmailID='" & Convert.ToString(Email.Text) & "' where Stu_ID=" & Convert.ToString(ID.Text) & "", con)
    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()
    Return "Updated Sucessfully"
End Function


The Delete Event:
At first, you need to create the OnRowDeleting Event from the event window of the GridView:

VB
Protected Sub DataGridView_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
    Dim Stu_ID As Label = DirectCast(DataGridView.Rows(e.RowIndex).FindControl("LblStuID"), Label)
    Dim id As Integer = Convert.ToInt32(Stu_ID.Text)
    Dim Message As String = obj.Delete_Data(id)
    Fill_Grid()
    Literal1.Text = Message
End Sub



The Delete_Data definition is:

SQL
Public Function Delete_Data(id As Integer) As String
    con.Open()
    cmd = New SqlCommand("Delete from Tbl_Student where Stu_ID=" & id & "", con)
    cmd.ExecuteNonQuery()
    con.Close()
    Return "Deleted Sucessfully"
End Function



Note: Please modify the code with your details.
 
Share this answer
 
Comments
gnani_pal 1-Apr-14 0:53am    
here i am using stored procedures in sql server data base conncetion. its is web appliction not windows. and i am trying in VB.NET in 3tier architecture

so please help me in which layer what should i write
Nimit Joshi 2-Apr-14 3:43am    
See, you can execute the query with the use of Stored Procedure. It is the Web Application and you can develop it in 3 tier architecture
you can rather use objectdatasource or sqldatasource and write your update and delete methods for it.
 
Share this answer
 
Comments
gnani_pal 1-Apr-14 0:43am    
here i am using stored procedures in sql server data base conncetion. its is web appliction not windows. and i am trying in VB.NET in 3tier architecture

so please help me in which layer what should i write

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900