Aspx: updating db with textbox does not work

Hi all,

I’ve been trying to resolve this issue for like 10 hours but with no luck. I am trying to load data from a db to text boxes and allow the user to enter his/her modifications and click a button to update the db with the entered value in the textboxes. The problem is the entered data are not sent to the db but the data that are loaded when the page is loaded is what it goes to the db. I also tried vb codes and javascript to change the data of the textbox but that did not work.

here is my code:

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Public Class BuyerProfile
    Inherits System.Web.UI.Page

    Private Sub BuyerProfile_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DataBinding

    End Sub



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'MsgBox(userid)
    
        If usergroup <> "b" Or isLogin = False Then
            Server.Transfer("Default.aspx")
        Else
            conn.Open()
            Dim cmd As New OracleCommand(sql, conn)
            p_userid = New OracleParameter("p_userid", OracleDbType.Decimal, ParameterDirection.Input)
            p_buyername = New OracleParameter("p_buyername", OracleDbType.Varchar2, ParameterDirection.Output)
            p_opassword = New OracleParameter("p_opassword", OracleDbType.Varchar2, ParameterDirection.Output)
            p_email = New OracleParameter("p_email", OracleDbType.Varchar2, ParameterDirection.Output)
            p_shippingaddress = New OracleParameter("p_shippingaddress", OracleDbType.Varchar2, ParameterDirection.Output)
            p_errorMsg = New OracleParameter("pErrorMsg", OracleDbType.Varchar2, ParameterDirection.Output)





            cmd = New OracleCommand("getBuyerInfo", conn)

            cmd.CommandType = CommandType.StoredProcedure


            ' declaring sizes of the db vars
            p_userid.Size = 6
            p_buyername.Size = 50
            p_opassword.Size = 50
            p_email.Size = 100
            p_shippingaddress.Size = 100
            p_errorMsg.Size = 100


            p_userid.Value = userid


            cmd.Parameters.Add(p_userid)
            cmd.Parameters.Add(p_buyername)
            cmd.Parameters.Add(p_opassword)
            cmd.Parameters.Add(p_email)
            cmd.Parameters.Add(p_shippingaddress)
            cmd.Parameters.Add(p_errorMsg)


            cmd.ExecuteNonQuery()
            'MsgBox(p_email.Value.ToString())
            txtFullName.Text = p_buyername.Value.ToString()

            txtEmail.Text = p_email.Value.ToString()
            txtAddress.Text = p_shippingaddress.Value.ToString()
            conn.Close()
        End If
        


    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
        'getf("txtFullName")
        MsgBox(txtFullName.Text)
        writeToF("txtFullName", "hahahaha")
        MsgBox(txtFullName.Text)

        'ASPNET_MsgBox(txtFullName.Text.)
        'ASPNET_MsgBox("=" & Request()
        'Dim key As String

        'For Each key As String In Request.ServerVariables.AllKeys
        'ASPNET_MsgBox(key & ": " & Request.ServerVariables(key))
        'Next

        Select Case txtcPassword.Text
            Case ""
                If txtNewPassword.Text <> "" Or txtNewPasswordConfirmation.Text <> "" Then
                    ASPNET_MsgBox("you need to enter your current password in order to change to a new one!")
                Else
                    conn.Open()
                    Dim cmd As New OracleCommand(sql, conn)
                    p_errorMsg = New OracleParameter("pErrorMsg", OracleDbType.Varchar2, ParameterDirection.Output)
                    p_userid = New OracleParameter("p_userid", OracleDbType.Decimal, ParameterDirection.Input)
                    p_buyername = New OracleParameter("p_buyername", OracleDbType.Varchar2, ParameterDirection.Input)
                    p_email = New OracleParameter("p_email", OracleDbType.Varchar2, ParameterDirection.Input)
                    p_shippingaddress = New OracleParameter("p_shippingaddress", OracleDbType.Varchar2, ParameterDirection.Input)
                    p_ipassword = New OracleParameter("p_ipassword", OracleDbType.Varchar2, ParameterDirection.Input)

                    cmd = New OracleCommand("update_buyerProfile", conn)
                    cmd.CommandType = CommandType.StoredProcedure


                    ' declaring sizes of the db vars
                    p_userid.Size = 6
                    p_buyername.Size = 50
                    p_ipassword.Size = 50
                    p_shippingaddress.Size = 100
                    p_email.Size = 100
                    p_errorMsg.Size = 100


                    p_userid.Value = userid
                    p_ipassword.Value = p_opassword.Value
                    p_shippingaddress.Value = txtAddress.Text
                    p_email.Value = txtEmail.Text
                    p_buyername.Value = txtFullName.Text

                    '(p_userid IN integer, p_buyername in varchar2, p_shippingaddress in varchar2,
                    'p_email in varchar2,p_ipassword in varchar2, pErrorMsg OUT varchar2)

                    cmd.Parameters.Add(p_userid)
                    cmd.Parameters.Add(p_buyername)
                    cmd.Parameters.Add(p_shippingaddress)
                    cmd.Parameters.Add(p_email)
                    cmd.Parameters.Add(p_ipassword)
                    cmd.Parameters.Add(p_errorMsg)
                    'ASPNET_MsgBox(p_userid.Value.ToString() & "," & p_buyername.Value.ToString() & "," _
                    '& p_shippingaddress.Value.ToString() & "," & p_email.Value.ToString() & "," _
                    '& p_ipassword.Value.ToString() & "," & p_errorMsg.Value.ToString())
                    'txtFullName.Text = "eeeeeeeeeeee"



                    'Dim t As String = p_opassword.Value.ToString()
                    cmd.ExecuteNonQuery()
                    'ASPNET_MsgBox(p_errorMsg.Value.ToString())
                    conn.Close()
                End If

            Case p_opassword.Value.ToString()

            Case Else
                ASPNET_MsgBox("Sorry, you have not entered the correct password ! <br> You may try to enter it again !")

        End Select
        

    End Sub

    
End Class
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="BuyerProfile.aspx.vb" Inherits="loginForm.BuyerProfile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Buyer Control Panel</title>
    <link rel="stylesheet" type="text/css" href="1st.css" />

   
    </style>

   
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
        }
        .style3
        {
            width: 187px;
        }
        .style4
        {
            height: 15px;
        }
        .style5
        {
            width: 187px;
            height: 15px;
        }
    </style>

   
    </head>
<body>
    <form id="form1" runat="server">
    <div align="center" id="mainDiv">
    <table id="mainTbl" cellpadding="0" cellspacing="0">
        <tr>
            <td align="center" colspan="2" id="headerCell">
                <table cellpadding="0" cellspacing="0" style="width:100%; height:71px;">
                    <tr>
                        <td id="lTop">
                            &nbsp;</td>
                        <td id="mTop">
                            &nbsp;</td>
                        <td id="rTop">
                            &nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td valign="top">
       <table id="mnuTbl" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                        
                            View Cart</td>
                    </tr>
                    <tr>
                        <td>
                            Order Status</td>
                    </tr>
                    <tr>
                        <td>
                            Orders History</td>
                    </tr>
                    <tr>
                        <td>
                            <a href="BuyerProfile.aspx">Edit Profile</a></td>
                    </tr>
                    <tr>
                        <td>
                            Log out</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;</td>
                    </tr>
                </table>
                
                
            </td>
            <td class="rightCol">
                <table id="ttt" class="style1">
                    <tr>
                        <td align="center" colspan="3" style="text-align: justify">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style4">
                            </td>
                        <td class="style5">
                            Full Name:</td>
                        <td class="style4">
                            <asp:TextBox ID="txtFullName" runat="server" Width="251px" 
                                EnableViewState="False"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style2">
                            &nbsp;</td>
                        <td class="style3">
                            Current Password:</td>
                        <td style="direction: ltr">
                            <asp:TextBox ID="txtcPassword" runat="server" Width="250px" TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style2">
                            &nbsp;</td>
                        <td class="style3">
                            New Password:</td>
                        <td>
                            <asp:TextBox ID="txtNewPassword" runat="server" Width="250px" 
                                TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style2">
                            &nbsp;</td>
                        <td class="style3">
                            New Password confirmation:</td>
                        <td>
                            <asp:TextBox ID="txtNewPasswordConfirmation" runat="server" Width="249px" 
                                TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style2">
                            &nbsp;</td>
                        <td class="style3">
                            Email:</td>
                        <td>
                            <asp:TextBox ID="txtEmail" runat="server" Width="249px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style2">
                            &nbsp;</td>
                        <td class="style3">
                            Shipping address:</td>
                                <td>
                                    <asp:TextBox ID="txtAddress" runat="server" Width="247px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" class="style2" colspan="3">
                                    <asp:Button ID="btnUpdate" runat="server" Text="update" />
                                </td>
                            </tr>
                        </table>
                    </td>
        </tr>
        </table>
        </div>
    </form>
</body>
</html>


Just skimmed (might have more problems), but where is your connection object? You can’t open the connection to the database without specifing a connection object.

Currently:


conn.Open()
Dim cmd As New OracleCommand(sql, conn)



Should be:



Dim conn As New OracleConnection("connect sting goes here")
Dim cmd As New OracleCommand(sql, conn)
conn.Open()

That could be your problem.

my connection object is declared as public in a Module file. And I’m pretty sure that there is a connection because I was able to print out the content of the “p_errorMsg” which is a return from the db stored procedure, which does the update.

I think I need to know something about using the textboxes and loading them with data on the page load event. I googled for that but I’ve not found anything yet.

Your try is really appericated, thanks !

the db stored procedure in case you needed to verfiy any doubts :

create or replace procedure update_buyerProfile(p_userid IN integer, p_buyername in varchar2, p_shippingaddress in varchar2,p_email in varchar2,p_ipassword in varchar2, pErrorMsg OUT varchar2)
is
begin
UPDATE tblbuyers
SET buyername=p_buyername, shippingaddress=p_shippingaddress
WHERE buyerid=p_userid;

UPDATE tblusers
SET email=p_email, password=p_ipassword
where UserID=p_userid;
pErrorMsg:=‘done!’;
commit;
EXCEPTION
WHEN OTHERS THEN
pErrorMsg:=‘No record WAS UPDATED !’;
end;
/
commit;
– those lines for testing the procedure in dos commnad line/unix shell
var id number;
var buyer varchar2(100);
var pass varchar2(100);
var email varchar2(100);
var addr varchar2(100);
var err varchar2(100);
set serveroutput on;
exec :id:=2;
exec getBuyerInfo(:id, :buyer,:addr, :email, :pass, :err);
exec update_buyerProfile(:id, :buyer,:addr, :email, :pass, :err);

exec :addr:=‘123 somethign st’;
exec update_buyerProfile(:id, :buyer,:addr, :email, :pass, :err);
exec dbms_output.put_line(:addr);

I’ve been workin’ on it for like 12 hours so far but with no luck. I need to get it ready for my presentation tomorrow even though my professor does not expect it to be ready completely but without I’ll have a hard time to give a good presentation.

Thank god !
I finally found a solution and I like to share it in case someone in the future needs it.

It’s very basic but because i am a php coder i thought that i can skip reading about the php and relying on the visual studio.net to write the codes for me.

the solution basicly is to load the data into the textboxes during the “intia” event not on “page load”

The Page_load event fires on every trip to your page, so you are overwriting
the data changed on the site with the Page_Load event assignments.
… so, your fresh, new values are trampled on when you post back to
update…

events fired in this order:

Init
Load viewstate
Process postback data (this is where your new data gets back to the
application)
Load (this is were you lose the data, and the original values are put back)
Send postback Change
Postback events
pre-render
save view state
render
dispose
unload

source:

You could also check the PostBack property of the page, ie.


 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 If Not Page.IsPostBack Then
   ' Fill the text boxes with Data retrieved from the DB
 End If
End Sub