更新vb.net中的数据 [英] update data in vb.net

查看:71
本文介绍了更新vb.net中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更新vb.net中的数据,更新vb.net中的代码

how to update data in vb.net, update code in vb.net

推荐答案

私有函数GetActID()

'动作Id Fetch

Dim objReader作为SqlDataReader

cmd.CommandText =选择ActId,来自Hrm_ActionMst的ActCode,其中ActCode ='&actCode&'

cmd =新的SqlCommand(cmd.CommandText,conn1)

objReader = cmd.ExecuteReader

当objReader.Read

如果actCode = objReader .GetValue(1)然后

Dim acid As Integer = objReader.GetValue(0)

objReader.Close()

返回酸

结束如果

结束时

objReader.Close()

返回False

结束功能

'---------------------------------------- ------------------------------



Private Sub BtnUpdate_Click( ByVal sender As System.Object,ByVal e As System.EventArgs)处理BtnUpdate.Click

如果txtcode.Text =那么

MsgBox(输入操作代码! ,MsgBoxStyle.Exclamation,错误)

txtcode.Focus()

返回

ElseIf txtdesc.Text =然后

MsgBox(输入操作说明!。,MsgBoxStyle.Exclamation,错误)

txtdesc.Focus()

返回

Else

Conn1.Open()

actID = GetActID()

Cmd.CommandText =update Hrm_ActionMst set ActCode =' &txtcode.Text&',CodeDescription ='&txtdesc.Text&'where ActId ='&actID&'

Cmd = New SqlCommand(Cmd.CommandText,Conn1)

Cmd.ExecuteNonQuery()

MsgBox(动作更新成功,MsgBoxStyle .MsgBoxRight)

Conn1.Close()

结束如果

End Sub
Private Function GetActID()
'Action Id Fetch
Dim objReader As SqlDataReader
cmd.CommandText = "select ActId,ActCode from Hrm_ActionMst where ActCode='" & actCode & "'"
cmd = New SqlCommand(cmd.CommandText, conn1)
objReader = cmd.ExecuteReader
While objReader.Read
If actCode = objReader.GetValue(1) Then
Dim acid As Integer = objReader.GetValue(0)
objReader.Close()
Return acid
End If
End While
objReader.Close()
Return False
End Function
'----------------------------------------------------------------------

Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
If txtcode.Text = "" Then
MsgBox("Enter Action Code !.", MsgBoxStyle.Exclamation, "Error")
txtcode.Focus()
Return
ElseIf txtdesc.Text = "" Then
MsgBox("Enter Action Description !.", MsgBoxStyle.Exclamation, "Error")
txtdesc.Focus()
Return
Else
Conn1.Open()
actID = GetActID()
Cmd.CommandText = "update Hrm_ActionMst set ActCode='" & txtcode.Text & "',CodeDescription='" & txtdesc.Text & "' where ActId='" & actID & "' "
Cmd = New SqlCommand(Cmd.CommandText, Conn1)
Cmd.ExecuteNonQuery()
MsgBox("Action Update Successfully", MsgBoxStyle.MsgBoxRight)
Conn1.Close()
End If
End Sub


这篇关于更新vb.net中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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