本文介绍了如何在asp.net中更新两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to update my status from '2' to '3', but my problem is data not update in database







Sub Update()    'UPDATE RECORD

        Dim strIDK As String = Me.txtIdKaunseling.Text

        If strIDK = "" Then Exit Sub

        If strIDK <> "" Then
            '---UPDATE IN TABLE SKP01_KaunselingPL---
            sql = "UPDATE dbo.SKP01_KaunselingPL SET SKP01_Status = '3' " _
                & "WHERE SKP01_KaunselingID = '" & strIDK & "'"

            If fnExec(sql, iTran:=2) = 1 Then
                setMsg(Me, msgBoxSaved, "strKey1")
            Else
                setMsg(Me, msgBoxSaveFailed, "strKey1")
            End If

            '---UPDATE IN TABLE SKP01_KaunselingDT---
            sql = "UPDATE dbo.SKP01_KaunselingDT SET SKP01_Status = '3'" _
                & "WHERE SKP01_KaunselingID = '" & strIDK & "'"

            If fnExec(sql, iTran:=2) = 1 Then
                setMsg(Me, msgBoxSaved, "strKey1")
            Else
                setMsg(Me, msgBoxSaveFailed, "strKey1")
            End If
        End If
    End Sub







This is my btnSave HTML







<div id="menu" class="toolbar">
        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/save.png" ToolTip="Save" CssClass="imgBtn" ValidationGroup="Check" Width="32" Height="32"/>
    </div>

推荐答案

If Session("strID") = "" 


如果会话(strID)是
设置为某个值,因为此行询问是否未设置strID ...



您需要先将if更改为:


if Session("strID") is set to some value because this line asks if strID is NOT set...

You need to change that first "if" to:

If Session("strID") IsNot Nothing AndAlso IsNumeric(Session("strID")) Then
' the rest of your function
End If





这会检查会话中是否存在strID并且它是一个数字(或CInt函数会引发错误)



This checks that strID exists in your session and that it is a number (or CInt function would throw an error)


这篇关于如何在asp.net中更新两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 10:12