Problem with Request Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suganya
    New Member
    • Dec 2006
    • 39

    #1

    Problem with Request Form

    Hi

    I have to retrieve the value from the DB & display on the textboxes which are in Default2.aspx based on the value entered in the textbox which is in Default.aspx.
    For that I have given the coding in Default.aspx as
    Code:
     
    <form id="form1" runat="server" method="post" action="Default2.aspx">
     
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
     
    <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
    If I type the value in the TextBox & click the button which is in Default.aspx then it should Redirect to the Default2.aspx & retrive & display the data from the DB.For that in Default2.aspx I have given the coding as
    Code:
     
    <form id="form1" runat="server" method="get" action="Default.aspx">
     
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    In Form Load, I have given the coding as

    Code:
     Imports System.Data.SqlClient 
    Imports System.Data
    Partial Class Default2
    Inherits System.Web.UI.Page
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
    Dim con As New SqlConnection("user id=sa;password=cast;database=sjc;server=AURORA-SERVER")
    con.Open()
    Dim sql As String = "select * from ITEMS where ID='" & Request.Form("a") & "'"
    Dim cmd As New SqlCommand(sql, con)
    Dim dr1 As SqlDataReader
    dr1 = cmd.ExecuteReader()
    While (dr1.Read())
    TextBox1.Text = dr1.GetValue(2).ToString()
    TextBox2.Text = dr1.GetValue(3).ToString()
    TextBox3.Text = dr1.GetValue(7).ToString()
    TextBox4.Text = dr1.GetValue(5).ToString()
    End While
    End Sub
    End Class
    But its not running & also it is not showing any error.
    Last edited by DrBunchman; Jun 3 '08, 12:36 PM. Reason: Added code tags - Please use the # button
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    1> It is possible that your ITEMS table has no rows with ID specified in the sql statement. You can goto the query anylyzer and check the results.

    2> You can debug your code by using Try Catch. So that you can display any database related error on the page where you are displaying data.

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      Hi suganya,

      Are you able to run your page in debug, step through it and see what is happening?

      Can you check that your sql string is correct - e.g. does the string generated by your code return records if you run it in Query Analyzer or similar?

      Dr B

      Comment

      Working...