Click here to Skip to main content
15,888,202 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to update my status from '2' to '3', but my problem is data not update in database


VB
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


ASP.NET
<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>
Posted
Updated 28-Sep-14 16:02pm
v4
Comments
Sinisa Hajnal 25-Sep-14 2:21am    
Several problems with this code:
- if your Session("strID") is an empty string CInt will throw an exception
- your update code shouldn't be concatenated, use parametrized query
- if your IDs are numbers, don't use chars / varchars
- if your statuses are numbers, use number columns not chars / varchars (you can even create STATUS table so you get number AND description as you need them while maintaining simple integer FK.

Finally, you didn't really pose a question here, what is your problem? Which error do you get? At which line? Or your code works, but doesn't remove the row from the grid?
U_Hanisa 25-Sep-14 2:33am    
Yes, that is my problem. I don't know what error in my coding. But when I click btnSave, it doesn't remove from the gridview. Can you help me?
Sinisa Hajnal 25-Sep-14 2:46am    
No, I can't. There is no btnSave in your code above, nor the handler for the same (unless you bind to Update).

I could if you provide more details.
If you check my first item from the last comment, you'll see that you get an error in CInt(Session("strID")) OR that your Session("strID") is NOT an empty string :)

Set a break point at If Session("strID") line, remove any catch handlers that "swallow" the errors, let the errors be seen.

Update your question - provide description of the intent of the code - what should be in strID? Where do you set it? Why do you test for empty string before going into saving block?
U_Hanisa 25-Sep-14 2:55am    
btnSave is Sub Update. Pls check my updated question. I don't understand what are you trying to say.
Sinisa Hajnal 25-Sep-14 3:08am    
OK. Slow and easy, answer each question, then we will proceed:
- Do you know what a breakpoint is? And how to set it?
- Do you have any try/catch blocks?
- Can you update your question with your btnSave HTML?
- Does saving the status work? That is, if you click btnSave, does it change in the database? Or none of it works? (this would be my guess)

- What should be stored in Session("strID")?
- Why are you testing it to be empty before saving? That is, what do you think If Session("strID") = "" does?

1 solution

First of all, the function Update will never get past
VB
If Session("strID") = "" 

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:
VB
If Session("strID") IsNot Nothing AndAlso IsNumeric(Session("strID")) Then
' the rest of your function
End If


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

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