 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 18th, 2004, 01:59 PM
|
|
Authorized User
|
|
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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))
|
|

August 18th, 2004, 02:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

August 18th, 2004, 02:56 PM
|
|
Authorized User
|
|
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

August 18th, 2004, 02:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

August 18th, 2004, 03:06 PM
|
|
Authorized User
|
|
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 19th, 2004, 07:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

August 19th, 2004, 09:59 AM
|
|
Authorized User
|
|
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 19th, 2004, 11:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

August 19th, 2004, 12:41 PM
|
|
Authorized User
|
|
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

August 20th, 2004, 07:41 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|
 |