我需要插入按钮和删除,搜索,更新Vb.Net中的按钮逻辑。我使用Sqlserver数据库使用存储过程的3层架构 [英] I Need insert Button And Delete,search,update Button Logic In Vb.Net. I Am Using Sqlserver Data Base using stored procedure's for 3 tier architecture

查看:65
本文介绍了我需要插入按钮和删除,搜索,更新Vb.Net中的按钮逻辑。我使用Sqlserver数据库使用存储过程的3层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人帮助我更新按钮和删除按钮逻辑的逻辑,这里我使用gridview与sqlserver,我的表名是TESTING,我的coloms是empid,empno,empadress。



请帮帮我

解决方案

嘿伙计,



更新活动:



首先,您需要从GridView的事件窗口创建OnRowUpdating事件:



 受保护的  Sub  DataGridView_RowUpdating(sender 作为 对象,e 作为 GridViewUpdateEventArgs)
Dim ID As Label = TryCast (DataGridView.Rows( e.RowIndex).FindControl( LblStuID ),标签)
Dim 名称作为 TextBox = TryCast (DataGridView.Rows(e.RowIndex).FindControl( TxtEditStuName) ,TextBox)
Dim 性别作为 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 电子邮件作为 TextBox = TryCast (DataGridView.Rows(e.RowIndex).FindControl( TxtEditStuEmailID),TextBox)

Dim 消息作为 字符串 = obj.Updata_Data(ID,Name,Gender.SelectedItem,Grad,PostGrad,Mobile,_
Email)
Fill_Grid()
Literal1.Text = Mess年龄
结束 Sub





Update_Data定义是:





 公共 功能 Updata_Data(ID 作为标签,名称 As  TextBox,listItem  As  ListItem,Grad  As  TextBox,PostGrad < span class =code-keyword> As  TextBox,Mobile  As  TextBox,_ 
电子邮件正如 TextBox) As 字符串
cmd =新的SqlCommand( 更新Tbl_Student设置Stu_Name ='& 转换 .ToString(名称。文字)& ',Stu_Gender ='& 转换 .ToString(listItem。 Text )& ',Stu_Graduation ='& 转换 .ToString(Grad。 Text )& ',Stu_PostGraduation ='& 转换 .ToString(PostGrad。 Text )& ',Stu_MobileNo =& 转换 .ToString(移动。文字)& ,Stu_EmailID ='& 转换 .ToString(电子邮件。文字)& '其中Stu_ID =& 转换 .ToString(ID。文字)& ,con)
con。 Open ()
cmd.ExecuteNonQuery()
con。关闭()
返回 已成功更新
结束 功能





删除事件:

首先,您需要从GridView的事件窗口创建OnRowDeleting事件:



 受保护的  Sub  DataGridView_RowDeleting(发件人作为  Object ,e  As  GridViewDeleteEventArgs)
Dim Stu_ID As Label = DirectCast (DataGridView.Rows(e.RowIndex).FindControl( LblStuID),标签)
Dim id As 整数 = Convert.ToInt32(Stu_ID.Text)
Dim 消息 As 字符串 = obj.Delete_Data(id)
Fill_Grid()
Literal1.Text =消息
结束 Sub







Delete_Data定义是:



 公共 函数 Delete_Data(id  As 整数) As  String 
con。打开()
cmd =新的SqlCommand( 从Tbl_Student删除,其中Stu_ID =& id& ,con)
cmd.ExecuteNonQuery()
con。关闭()
返回 < span class =code-string>已成功删除
结束 功能







注意:请修改代码并附上您的详细信息。


< blockquote>您可以使用objectdatasource或sqldatasource并为其编写更新和删除方法。


请参阅:

http://www.dotnetfunda.com/articles/show/71/3-tier-architecture-in -aspnet-with-csharp [ ^ ]

http://dreaminvent.wordpress.com/2012/09/27/ 3层架构在asp-net-with-c / [ ^ ]



以上链接在c#中。将其转换为Vb.net 此处 [ ^ ]和/或这里 [ ^ ]

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

解决方案

Hey Buddy,

The Update event:

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

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:


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:

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:

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.


you can rather use objectdatasource or sqldatasource and write your update and delete methods for it.


See this:
http://www.dotnetfunda.com/articles/show/71/3-tier-architecture-in-aspnet-with-csharp[^]
http://dreaminvent.wordpress.com/2012/09/27/3-tier-architecture-in-asp-net-with-c/[^]

The above links are in c#. Convert it to Vb.net here[^] and/or here[^]


这篇关于我需要插入按钮和删除,搜索,更新Vb.Net中的按钮逻辑。我使用Sqlserver数据库使用存储过程的3层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆