Link to home
Start Free TrialLog in
Avatar of seloh
seloh

asked on

Display data from database

Hi ... I'm new to ASP.net and I'm trying to create an extra page for an existing application.
The page is supposed to retrieve some information form a database and display it!

I have the following!
Feedback.aspx
=====
<!-- #include file = "../scripts/include/FBrender.aspx" -->
<asp:Label ID="VraagID" runat="server" visible="False"></asp:Label><br>
<asp:Label ID="CaseID" runat="server" visible="False"></asp:Label><br>
<HTML>
<HEAD>
<TITLE>Feedback</TITLE>
</HEAD>
<BODY>

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
  <TR>
    <TD VALIGN=TOP>
      <asp:Label ID="FeedBack" runat="server"></asp:Label>
    </TD>
  </TR>
</TABLE>

</BODY>
</HTML>
=====
FBrender.aspx
=====
<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<script runat="server">
Public connectionstring As String = System.Configuration.ConfigurationSettings.AppSettings("connectionstring")

Sub Page_Load
  Dim QuestionID = VraagID.text
  Dim intCaseID = CaseID.text
  Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)

  Dim StrSql As String = "SELECT Feedback FROM RI_CaseA WHERE Case_ID = '"& intCaseID &"' AND VraagID = '"& QuestionID &"' ORDER BY AntwoordVolgorde"
  Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(StrSql, sqlConnection)

  sqlConnection.Open
  Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

  if dataReader.Read then
    FeedBack.text = dataReader("Feedback")
  End if
  dataReader.Close
  dataReader = Nothing
  sqlConnection.Close

  page.databind
end sub
</script>
<html>
<head>
</head>
<body>
</body>
</html>
=====

The SQL-statement
[SELECT Feedback
FROM RI_CaseA
WHERE Case_ID = '"& intCaseID &"' AND VraagID = '"& QuestionID &"'
ORDER BY AntwoordVolgorde]
retrieves several records and I have to display them all.
I use following syntax to call the page
http://..../feedback.aspx?CaseID=1&VraagID=2

I'm probably forgetting something really simple!!

Thnx in advance
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You haven't said what the problem is !! Are you getting an error ? Or is it simply not showing anything ?
Avatar of seloh
seloh

ASKER

Sorry!
There's nothing showing up ... I get an empty page!
Are you going to use the FBrender.aspx code on other pages? Wondering why you separated the pages.
Have you tried putting the FBrender.aspx code on the same page as Feedback.aspx? Does it pull data then?

Dont see the System.Data.SQLClient namespace reference anywhere either....it could be that.
You dimmed your datareader and called the namespace, but it isn't in the page directive.

Include files are getting pretty much obsolete in .NET also...if you're practicing good OOP, then SQL and datasets should be in a separate class file or even separate project that gets referenced in your interface project.

If you're moving from ASP to ASP.Net, I would suggest moving to Visual Studio.Net as well.

I hate to say it...but Microsoft VS.Net is the best .Net tool.... .Net is fairly different from ASP and although you can use different IDE's and notepad for ASP, you're making it a lot harder on yourself not using VS.Net.

Plus right now, VS.Net 2005 is in beta2 with a "Go Live" guarantee from MS.  And it is free to order the full app on DVD.  Also, the express version is free for download.

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial