Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send form values-basic question 2

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,
This is first time i am trying to create a application in .net (using my asp logic)

OK..i have a created a form...lets say with two text fields and a submit button...lets say this default.aspx.here is how i have the code...showing only the relevant parts
Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Default.aspx.vb" Inherits="olpat._Default"%>

<form id="announce" action="process.aspx" method="post" runat="server">
<asp:textbox id="FName" runat="server"></asp:textbox>
<asp:textbox id="LName" runat="server"></asp:textbox>
<asp:button id="Announce" runat="server" Text="Announce Name"></asp:button>
</form>

ok now...as you can see i have said method="post" action="process.aspx"

now how can i grab these values in the process.aspx page and display the name or doing some insert statement...

let me know if you need more info...

Thanks...

-DNG

 
I'm not sure why that would error but you shouldn't be using response.write anyway. Try using a Hyperlink control instead and setting the NavigateURL property.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
yeah you are correct...it is not that line...when i commented it it showed me another line but it is pointing to the InsertIntoDb()...here is my complete code for this sub...am i making any mistake in collecting form variables...

Code:
Private Sub InsertIntoDb()

        Dim sConnection As String
        Dim strSQL As String
        Dim dbConn As OleDb.OleDbConnection
        Dim dbCmd As OleDb.OleDbCommand
        Try
            'collect form values
            Dim sname As String = Request.Form("sname")
            Dim spractice As Integer = Request.Form("spractice"), "'", "''")
            Dim subdate As String = Request.Form("subdate")
            Dim empname As String = Request.Form("empname")
            Dim suffix As String = Request.Form("suffix")
            Dim offloc As String = Request.Form("offloc")
            Dim businessseg As Integer = Request.Form("businessseg")
            Dim pracarea As Integer = Request.Form("pracarea")
            Dim briefexp As String = Request.Form("briefexp")
            Dim posres As String = Request.Form("posres")
            Dim placement As String = Request.Form("placement")
            Dim affiliation As String = Request.Form("affiliation")
            Dim accesskey As String = GetRandomKey(5)

            sConnection = ConfigurationSettings.AppSettings("olpat")

            strSQL = " INSERT INTO AnnouncePosition(SubmitterName," & _
                     " SubmitterPractice,SubmissionDate, " & _
                     " EmpName,EmpSuffix,OfficeLocation,BusinessSegment," & _
                     " PracticeArea, CurrentPosition, BriefExp, PositionResp" & _
                     " TargetPlacement, Affiliations, ActiveInd, Status, Comments, Accesskey) VALUES" & _
                     " ('" & sname & "','" & spractice & "','" & subdate & "','" & suffix & "', " & _
                     " '" & offloc & "','" & businessseg & "','" & pracarea & "','" & briefexp & "'," & _
                     " '" & posres & "','" & placement & "','" & affiliation & "',0,'X','','" & accesskey & "')"

            dbConn = New OleDb.OleDbConnection(sConnection)
            dbConn.Open()

            dbCmd = New OleDb.OleDbCommand(strSQL, dbConn)
            dbCmd.ExecuteNonQuery()
            Errorbox.Visible = False
            lblConfirmation.Visible = False

        Catch ex As Exception
            Errorbox.Text = ex.ToString & "<br>"
            Errorbox.Visible = True
        Finally
            lblConfirmation.Text = "Your Position Announcement is submitted." & "<br>" & " A confirmation email is sent to you with the access key using which you can check the status of your announcement." & "<br>" & " Thank You for using OLPAT"
            lblConfirmation.Visible = True
            'Response.Write("<a href=""[URL unfurl="true"]http://testserver/olpat"">Go[/URL] Back</a>")
            dbConn.Close()
        End Try

    End Sub

Do you see anything suspicious...
Thanks.

-DNG
 
oops...this line:
Dim spractice As Integer = Request.Form("spractice"), "'", "''")

is a typo...shud be

Dim spractice As Integer = Request.Form("spractice")

-DNG
 
First of all what are you using to develop this application as it will make it much easier if you use a tool with debugging capabilities (so you can step through the code a line at a time and see where the error occurs, as at the moment you can't tell us what error you are getting so it's quite hard to help you).

Secondly, I'm still not sure why you are using two pages (and using Server.Transfer). It would be much easier to do it all in your default.aspx page as you wn't have to collect your variables via Request.Form.

Thirdly, rather than build up an insert statement as you have done, I'd suggest using parameters as they will cope with "'" signs (and other special characters) and they will also protect you against SQL Injection attacks.

There is a lot of changes that I have suggested here, but I really think it's worth doing properly and using a tool with debug capabilities will especially help you with any errors.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm,

thank you for your suggestions...i was just trying to learn how to pass variables from one page to the other...it is just a test thing...i have learnt how to do the post back to the same page...i was just eager to create one page that does this variable transfer thing...

i debugged my code line by line and it turned out that i havent set the oledb provider...

can you show me the equivalent code for sqlclient instead of oledb...i mean simple insert code using sqlclient

-DNG
 
can you show me the equivalent code for sqlclient instead of oledb...i mean simple insert code using sqlclient
It's fairly easy. Just replace the Oledb class with SQLClient (e.g. OleDb.OleDbConnection with SqlClient.SQLConnection, OleDb.OleDbCommand with SQLClient.SQLCommand etc)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you very much...you guys have been really patient and helpful...
stars for you
-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top