Initial data added but not updated

M

Me LK

I have a page that will allow a user to add new data to a database the
first time they view the page and then allows them to return to add
more data or to update existing data. The initial adding of the data
works fine and all data added to first time the user sees the document
is put into the database. The update doesn't work, however. There is
no error. The page redirects as it is supposed to but there is no new
data.

VB 1.1


code behind
_____________________________________________________________________
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
' Create Instance of Connection and Command Object


'State.SelectedIndex = 0
Dim connection1 As New SqlConnection(connectionString)
Dim Command1 As New SqlCommand("UpdateAddress", connection1)
Command1.CommandType = CommandType.StoredProcedure
Command1.Parameters.Add("@CustomerID",
Context.Session("CustomerID"))
Command1.Parameters.Add("@first", txtFName.Text)
Command1.Parameters.Add("@Last", txtLastName.Text)
Command1.Parameters.Add("@Address1", txtStreetAddress.Text)
Command1.Parameters.Add("@Address2", txtStreetAddress2.Text)
Command1.Parameters.Add("@City", txtCity.Text)
Command1.Parameters.Add("@State", State.DataValueField)
Command1.Parameters.Add("@Zip", txtZip.Text)
Command1.Parameters.Add("@phone", txtPhone.Text)


' update address
connection1.Open()
Command1.ExecuteNonQuery()
connection1.Close()
_______________________________________________________________________
Stored proceedure

(@CustomerID int,
@First varchar (50),
@Last varchar (50),
@Address1 varChar (100),
@Address2 varChar (100),
@City varChar (100),
@State varChar (50),
@Zip varChar (50),
@Phone varChar (50)
)

as
Update tblCustomers
SET [first] = @first, [last] = @last, HomeAddress = @Address1,
HomeAddress2 = @Address2, City = @city,
@State = state, @Zip = Zip, @Phone = phone
Where CustomerID= @CustomerID


_____________________________________________________

The same code is used for the initial addition of data as well as the
update. Initial works fine but update does not.

Any suggestions?
 
M

Mark Rae [MVP]

The update doesn't work, however. There is no error.

Well, for a start you don't have any exception handling in your code -
that's the first thing to fix.
Command1.Parameters.Add("@CustomerID", Context.Session("CustomerID"))

When you step through the code, is that line correctly adding the
CustomerID?

When you set a trace on your database, what is the actual SQL statement that
the stored procedure is sending to the database engine?
 
M

Me LK

TI fiddled around and changed a bit of code so now I know that the
correct customerID is being sent. When I stepped through the code I
noticed that the changes that were placed into the text boxes were not
shown. The original values are what is being sent to the database
from the document. So my problem is in the code not the stored
procedure and database.
 
M

Mark Rae [MVP]

TI fiddled around and changed a bit of code so now I know that the
correct customerID is being sent. When I stepped through the code I
noticed that the changes that were placed into the text boxes were not
shown. The original values are what is being sent to the database
from the document. So my problem is in the code not the stored
procedure and database.

Are you fetching the record from the database every time the page loads,
even on postback?
 
M

Me LK

Aha! That was it. I missplaced the end if from the If Not
Page.IsPostBack and it was rebinding the data from the pageload.
Thanks. I appriciate your help.

LK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top