Passing Data between aspx pages

T

tjonsek

This is my first attempt to develop a form in .net to insert and update
data in a database based upon user input. I'm pretty familiar with ASP,
yet I'm finding some of the differences frustrating.
Page One allows a user to enter a record number and view details to
make sure the correct record was chosen. If they entered the correct
record number, fields open up to allow them to enter the rest of the
form. I have some basic data validation for dates and required fields.
On the btnSubmit_onclick() if the page is valid, I do a server.transfer
to a second page. The intent is for Page Two to pick up the values
entered in the textbox and update the database with the new
information. If for some reason, the transfer does not succeed, I
display a message to the user that the update failed.
For some reason, I cannot get the transfer and update to happen
successfully. I've debugged my way far enough to finally get the page
to transfer, but the update fails.
As far as my update statement goes, it was originally a stored proc,
but I had problems creating parameters and decided to go this route. If
you know of any really good online helps for stored procs with .NET
please let me know.

Here is the code from Page One:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Approved.aspx.vb" Inherits="Approved.WebForm1"
Classname="Source" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="VB" runat="server">
Public ReadOnly Property getUnionRep() As String
Get
Return unionRep.Text
End Get
End Property
Public ReadOnly Property getAreaUnionRep() As String
Get
Return areaUnionRep.Text
End Get
End Property
'More values are also passed. For clarity, I deleted these.
</script>
</HEAD>

Here is the code for Page Two:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="approvedSubmit.aspx.vb" Inherits="Approved.WebForm2"%>
<%@ Reference Page="Approved.aspx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
Dim sql As String
Dim objSource As Source

objSource = CType(context.Handler, Source)
dim unionSign as string
dim unionRep as string
dim areaUnionRep as string
dim areaUnionRepSign as string
dim unionComm as string
dim companyCoord as string
dim companySign as string
dim maintSupt as string
dim maintSuptSign as string
dim coordComm as string

unionSign = objSource.getUnionSign.text
unionRep = objSource.getUnionRep.text
areaUnionRep = objSource.getAreaUnionRep.text
areaUnionRepSign = objSource.getAreaUnionRepSign.text
unionComm = objSource.getUnionComm.text
companyCoord = objSource.getCompanyCoord.text
companySign = objSource.getCompanySign.text
maintSupt = objSource.getMaintSupt.text
maintSuptSign = objSource.getMaintSuptSign.text
coordComm = objSource.getCoordComm.text

sql = "Update ContractOut1 Set unionRep='" & unionRep & "',"
& _
" unionSign='" & unionSign & "',areaUnionRep='" & areaUnionRep
& "'," & _
" areaUnionRepSign='" & objSource.areaUnionRepSign & "'," & _
" unionComm='" & unionComm & "',companyCoord ='" &
companyCoord & "'," & _
" companySign='" & companySign & "',mainSupt='" & MaintSupt &
"'," & _
" maintSuptSign='" & maintSuptSign & "',coordComm='" &
coordComm & "'," & _
" approved='yes' where ContractOut1.ID='" & txtWO & "'"

SqlConnection1.Open()
SqlSelectCommand1.Connection = SqlConnection1
SqlSelectCommand1.CommandType = CommandType.Text
SqlSelectCommand1.CommandText = sql

Try
SqlSelectCommand1.ExecuteNonQuery()
lblUpdateSuccess.Visible = True
btnSuccess.Visible = True
Catch ex As Exception
lblFail.Visible = True
btnFail.Visible = True

End Try

End Sub

</script>
 
W

W.G. Ryan MVP

Paramaterizing the queries is the key... If you check out SqlCommand on MSDN
and check out Parameters, there are some good examples there. This looks
like the source of your problem.
 
P

Phenom

I will go through MSDN again. Actually, that is where I am getting all
my info. I don't have training in .NET. It is simply a trial by fire
process for me. When I originally attempted the Stored Procedure, I
continually got syntax errors when creating and setting values to my
parameters. I'll try once more. If this doesn't work, I'll post my
error message as a new question.
Thanks.
 

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

Top