Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 18th, 2004, 01:59 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data not getting updated

On clicking update button, I am moving form fields to the variables and using those variables to update the table. While debugging I found that the form fields do not contain the updated data. What am I missing here.

        Dim Jname As String = txtJurisName.Text
        Dim Jaddress As String = txtJurisAddr.Text
        Dim JCity As String = txtJurisCity.Text and so on...

and then I am using Jaddress, JCity to update the table as follows:-
Dim cmd As New SqlCommand("UPDATE tbl_jurisdiction SET JADDRESS = '" & Jaddress & "',JCity='" & JCity & "'....... & "' where JNAME = '" & Jname & "'", New SqlConnection(strConn))


  #2 (permalink)  
Old August 18th, 2004, 02:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

What are you updating? Data grid, or a row of textboxes? Could the name not be a correct name in the database and it's not finding it? Also, did you consider using an ID number, because what if you have a person with more than one name?

Brian
  #3 (permalink)  
Old August 18th, 2004, 02:56 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi-
I am updating database from various textboxes(No datagrid). Also, I am using the primary key JName to update it(Please see the update statement). txtJurisAddr.Text is a field on the form. When I change the text, it does not contain the changed value, it still has the old value and that is why it assigns the old value to JAddress field. How will the change take affect. Do I need to write code in JADDress_textchanged method? How will the textbox get the new value that I am entering?

  #4 (permalink)  
Old August 18th, 2004, 02:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Could you post the rest of the update code? I only see when you create the command statement, but nothing is executed. In addition, you are entering in the value into the textbox, when you hit update, those should be the new values, correct? Do you do something to the values? Also, do you use labels to display the field and use textboxes separately to edit the data?

Posting more code than that will help me understand the problem better.

Brian
  #5 (permalink)  
Old August 18th, 2004, 03:06 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code from my update_click method. I have used some constant fields for now:-

  Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim strConn As String = "data source=gsidbmsrb2;packet size=4096;user id=sa;password='blue';persist " & _
         "security info=False;initial catalog=TestPubs"

        Dim Jname As String = txtJurisName.Text
        Dim Jaddress As String = txtJurisAddr.Text
        Dim JCity As String = txtJurisCity.Text
        Dim JState As String = lstState.SelectedValue
        Dim JZip As String = txtJurisZip.Text
        Dim Jwebsite As String = txtWebsite.Text
        Dim CName As String = txtContactName.Text
        Dim CPhone As String = txtContactPhone.Text
        Dim cphoneExtq As String = txtExtn.Text
        Dim cemail As String = txtContactEmail.Text
        Dim WorkDate As Date = Now()
        Dim tmpDateTime As DateTime = WorkDate
        WorkDate = System.String.Format("{0:MM/dd/yyyy}", tmpDateTime)
        Dim IntroductionDate As Date = #2/2/2002#
        Dim HearingDate As Date = #3/3/2003#
        Dim AdoptionDate As Date = #4/4/2004#
        Dim Status As String = rdbStatus.SelectedValue
        Dim Jtype As String = rdbType.SelectedValue
        Dim SubmittedBy As String = txtSubmittedBy.Text
        Dim Mdate As Date = #5/5/2005#
        Dim Mcomments As String = txtComments.Text
        Dim OText As String = txtOrdinanceText.Text
        Dim OHistory As String = txtOrdHistory.Text
        Dim Ostatus As String = " "
        Dim Consultant As String = DdlConsultant.SelectedValue
        Dim PCIAAction As String = txtPCIAAction.Text
        Dim MAction As String = txtMaction.Text
        Dim LastModby As String = Me.Session("User")
        Dim LastModDate As Date = Now()


        Dim cmd As New SqlCommand("UPDATE tbl_jurisdiction SET JADDRESS = '" & Jaddress & "',JCity='" & JCity & "',JState='" & JState & "',JZip='" & JZip & "',JWebsite= '" & Jwebsite & "',CName= '" & CName & "',CPhone = '" & CPhone & "',CPhoneExtq= '" & cphoneExtq & "',CEmail= '" & cemail & "',WorkDate= '" & WorkDate & "',HearingDate= '" & HearingDate & "',AdoptionDate= '" & AdoptionDate & "',IntroductionDate = '" & IntroductionDate & "',Status= '" & Status & "',SubmittedBy= '" & SubmittedBy & "',MDate= '" & Mdate & "',MComments= '" & Mcomments & "',OText= '" & OText & "',OHistory= '" & OHistory & "',PCIAAction = '" & PCIAAction & "',MAction= '" & MAction & "',JType = '" & Jtype & "',Consultant= '" & Consultant & "',LastModby = '" & LastModby & "',LastModDate='" & LastModDate & "' where JNAME = '" & Jname & "'", New SqlConnection(strConn))

        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        Server.Transfer("AllOrdinances.aspx")
    End Sub

  #6 (permalink)  
Old August 19th, 2004, 07:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Where are you server.Transferring to? If you aren't accessing the form data from the Context.Handler property, that's why you are losing the data.

Brian
  #7 (permalink)  
Old August 19th, 2004, 09:59 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am server transferring because after update, I want to go back to the previous page and not stay on the same page. The record would have been updated by then.

  #8 (permalink)  
Old August 19th, 2004, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Are you requering the data there then? Because that is what has to happen; the data won't be present by default.

Posting that code may help also.

Brian
  #9 (permalink)  
Old August 19th, 2004, 12:41 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, Here is the scenario. I have a datagrid and edit link for each row. When I click on the Edit, a new page is displayed with all the information(using a select clause). I can see all the information on the page... the data is there. Then I modify some data say address (txtJurisAddr.Text). Where is this new address stored? I thought txtJurisAddr.Text will store the new address, but after debugging I found that it still has the old address. If I can get this modified address, I can update the record. I have checked by hardcoding the address field in my code behind file and update works just fine. May be I need to use sqldataadapter!

  #10 (permalink)  
Old August 20th, 2004, 07:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The new address is stored in the text box. SQLDataAdapter is a good way to go; however, do you retrieve the record to edit using the Page_Load method? If so, do you have your code between:

If (Not Page.IsPostBack) Then
  'Code here
End If

Sounds like the issue is it reloads the data and overwrites it on load.

Brian
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database not getting updated vsc33 VB How-To 4 May 15th, 2008 10:30 AM
how i can read updated data from other website eswarjava Pro JSP 1 January 11th, 2008 03:42 AM
updated report dominikm86 Crystal Reports 0 May 28th, 2007 01:03 PM
Database not updated tiredcat Visual Basic 2005 Basics 0 April 24th, 2007 08:49 PM
OPeration must be updated khzahid Classic ASP Basics 1 April 27th, 2005 06:01 PM



All times are GMT -4. The time now is 06:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.