I'm completely new to ASP.NET programming, so please accept my apologies in
advance for asking what is probably an obvious question. :-)
I'm trying to write a page which will display the contents of an SQL record.
I've added the following code to a file called default.aspx:
<html>
<head>
<title>My sample application </title>
</head>
<body>
<p> Output a database record:</p>
<%@ Page Language="C#" Debug="true" %>
<%@ import namespace="Syst em.Data" %>
<%@ import namespace="Syst em.Data.SqlClie nt" %>
<script language="c#" runat="server">
public void Page_Load(objec t sender, EventArgs e) {
SqlConnection objConn = new SqlConnection(" Server=serverna me;
Database=databa se; UId=username; Pwd=password");
objConn.Open();
string strQuery = "select * from tablename where field =
'value'";
SqlCommand objCmd = new SqlCommand(strQ uery, objConn);
objCmd.CommandT ype = CommandType.Tex t;
SqlDataReader objDR = objCmd.ExecuteR eader();
objDR.Read();
Response.Write( objDR["field"] + "<br>");
objConn.Close() ;
}
</script>
<p>Thus ends my query. </p>
</body>
</html>
The code executes properly and produces the expected results, however its
printing those results at the top of the page before any of the html. (Even
though the code is sandwiched between html code)
What am I doing wrong? :-)
Thank You,
Brad 5 5490
Brad Baker wrote: I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-)
I'm trying to write a page which will display the contents of an SQL record. I've added the following code to a file called default.aspx:
<html> <head> <title>My sample application </title> </head> <body> <p> Output a database record:</p> <%@ Page Language="C#" Debug="true" %> <%@ import namespace="Syst em.Data" %> <%@ import namespace="Syst em.Data.SqlClie nt" %> <script language="c#" runat="server"> public void Page_Load(objec t sender, EventArgs e) { SqlConnection objConn = new SqlConnection(" Server=serverna me; Database=databa se; UId=username; Pwd=password"); objConn.Open(); string strQuery = "select * from tablename where field = 'value'"; SqlCommand objCmd = new SqlCommand(strQ uery, objConn); objCmd.CommandT ype = CommandType.Tex t; SqlDataReader objDR = objCmd.ExecuteR eader(); objDR.Read(); Response.Write( objDR["field"] + "<br>"); objConn.Close() ; } </script> <p>Thus ends my query. </p> </body> </html>
The code executes properly and produces the expected results, however its printing those results at the top of the page before any of the html. (Even though the code is sandwiched between html code)
What am I doing wrong? :-)
Don't use Response.Write in Page_Load. As a matter of fact, don't
use Response.Write at all. This is old style ASP programming.
In ASP.NET, you should put a label control on the page, and use
Label1.Text="wh atever";
--
Riki
Brad you can also bind it to a control like datagrid,datali st repeater etc.
depending what you need.
Patrick
"Brad Baker" <br**@nospam.no spam> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. .. I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-) I'm trying to write a page which will display the contents of an SQL record. I've added the following code to a file called default.aspx: <html>
<head>
<title>My sample application </title>
</head>
<body>
<p> Output a database record:</p> <%@ Page Language="C#" Debug="true" %>
<%@ import namespace="Syst em.Data" %>
<%@ import namespace="Syst em.Data.SqlClie nt" %>
<script language="c#" runat="server"> public void Page_Load(objec t sender, EventArgs e) {
SqlConnection objConn = new SqlConnection(" Server=serverna me; Database=databa se; UId=username; Pwd=password");
objConn.Open(); string strQuery = "select * from tablename where field = 'value'";
SqlCommand objCmd = new SqlCommand(strQ uery, objConn); objCmd.CommandT ype = CommandType.Tex t;
SqlDataReader objDR = objCmd.ExecuteR eader();
objDR.Read();
Response.Write( objDR["field"] + "<br>");
objConn.Close() ; }
</script> <p>Thus ends my query. </p>
</body>
</html> The code executes properly and produces the expected results, however its printing those results at the top of the page before any of the html. (Even though the code is sandwiched between html code) What am I doing wrong? :-) Thank You,
Brad
Hmm... thanks for the suggestions. Although I don't really want to output
the results as a button label.
I don't think I want a data grid or a data list repeater either? (Although
I'm not completely sure what either of those are)
All I want to do is output the contents of one record and put it in a table.
For instance:
<table>
<tr><td>Announc ement</td></tr>
<tr><td> <% PRINT MY RECORD HERE %> </td></tr>
<table>
Would I want to do that with a data list repeater even though I am sure
there there will only be one record?
Thanks Again,
Brad
"Patrick.O. Ige" <na********@hot mail.com> wrote in message
news:O$******** ******@TK2MSFTN GP03.phx.gbl... Brad you can also bind it to a control like datagrid,datali st repeater etc. depending what you need. Patrick "Brad Baker" <br**@nospam.no spam> wrote in message news:%2******** ********@TK2MSF TNGP02.phx.gbl. .. I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-) I'm trying to write a page which will display the contents of an SQL record. I've added the following code to a file called default.aspx: <html>
<head>
<title>My sample application </title>
</head>
<body>
<p> Output a database record:</p> <%@ Page Language="C#" Debug="true" %>
<%@ import namespace="Syst em.Data" %>
<%@ import namespace="Syst em.Data.SqlClie nt" %>
<script language="c#" runat="server"> public void Page_Load(objec t sender, EventArgs e) {
SqlConnection objConn = new SqlConnection(" Server=serverna me; Database=databa se; UId=username; Pwd=password");
objConn.Open(); string strQuery = "select * from tablename where field = 'value'";
SqlCommand objCmd = new SqlCommand(strQ uery, objConn); objCmd.CommandT ype = CommandType.Tex t;
SqlDataReader objDR = objCmd.ExecuteR eader();
objDR.Read();
Response.Write( objDR["field"] + "<br>");
objConn.Close() ; }
</script> <p>Thus ends my query. </p>
</body>
</html> The code executes properly and produces the expected results, however its printing those results at the top of the page before any of the html. (Even though the code is sandwiched between html code) What am I doing wrong? :-) Thank You,
Brad
Actually a repeater is just what I wanted. Thanks for the help! :-)
Brad
"Brad Baker" <br**@nospam.no spam> wrote in message
news:uj******** ********@TK2MSF TNGP04.phx.gbl. .. Hmm... thanks for the suggestions. Although I don't really want to output the results as a button label.
I don't think I want a data grid or a data list repeater either? (Although I'm not completely sure what either of those are)
All I want to do is output the contents of one record and put it in a table. For instance:
<table> <tr><td>Announc ement</td></tr> <tr><td> <% PRINT MY RECORD HERE %> </td></tr> <table>
Would I want to do that with a data list repeater even though I am sure there there will only be one record?
Thanks Again, Brad "Patrick.O. Ige" <na********@hot mail.com> wrote in message news:O$******** ******@TK2MSFTN GP03.phx.gbl... Brad you can also bind it to a control like datagrid,datali st repeater etc. depending what you need. Patrick "Brad Baker" <br**@nospam.no spam> wrote in message news:%2******** ********@TK2MSF TNGP02.phx.gbl. .. I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-) I'm trying to write a page which will display the contents of an SQL record. I've added the following code to a file called default.aspx: <html>
<head>
<title>My sample application </title>
</head>
<body>
<p> Output a database record:</p> <%@ Page Language="C#" Debug="true" %>
<%@ import namespace="Syst em.Data" %>
<%@ import namespace="Syst em.Data.SqlClie nt" %>
<script language="c#" runat="server"> public void Page_Load(objec t sender, EventArgs e) {
SqlConnection objConn = new SqlConnection(" Server=serverna me; Database=databa se; UId=username; Pwd=password");
objConn.Open(); string strQuery = "select * from tablename where field = 'value'";
SqlCommand objCmd = new SqlCommand(strQ uery, objConn); objCmd.CommandT ype = CommandType.Tex t;
SqlDataReader objDR = objCmd.ExecuteR eader();
objDR.Read();
Response.Write( objDR["field"] + "<br>");
objConn.Close() ; }
</script> <p>Thus ends my query. </p>
</body>
</html> The code executes properly and produces the expected results, however its printing those results at the top of the page before any of the html. (Even though the code is sandwiched between html code) What am I doing wrong? :-) Thank You,
Brad
You are welcome brad
Patrick
"Brad Baker" <br**@nospam.no spam> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. .. Actually a repeater is just what I wanted. Thanks for the help! :-)
Brad
"Brad Baker" <br**@nospam.no spam> wrote in message news:uj******** ********@TK2MSF TNGP04.phx.gbl. .. Hmm... thanks for the suggestions. Although I don't really want to output the results as a button label.
I don't think I want a data grid or a data list repeater either? (Although I'm not completely sure what either of those are)
All I want to do is output the contents of one record and put it in a table. For instance:
<table> <tr><td>Announc ement</td></tr> <tr><td> <% PRINT MY RECORD HERE %> </td></tr> <table>
Would I want to do that with a data list repeater even though I am sure there there will only be one record?
Thanks Again, Brad "Patrick.O. Ige" <na********@hot mail.com> wrote in message news:O$******** ******@TK2MSFTN GP03.phx.gbl... Brad you can also bind it to a control like datagrid,datali st repeater etc. depending what you need. Patrick "Brad Baker" <br**@nospam.no spam> wrote in message news:%2******** ********@TK2MSF TNGP02.phx.gbl. .. I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-) I'm trying to write a page which will display the contents of an SQL record. I've added the following code to a file called default.aspx: <html>
<head>
<title>My sample application </title>
</head>
<body>
<p> Output a database record:</p> <%@ Page Language="C#" Debug="true" %>
<%@ import namespace="Syst em.Data" %>
<%@ import namespace="Syst em.Data.SqlClie nt" %>
<script language="c#" runat="server"> public void Page_Load(objec t sender, EventArgs e) {
SqlConnection objConn = new SqlConnection(" Server=serverna me; Database=databa se; UId=username; Pwd=password");
objConn.Open(); string strQuery = "select * from tablename where field = 'value'";
SqlCommand objCmd = new SqlCommand(strQ uery, objConn); objCmd.CommandT ype = CommandType.Tex t;
SqlDataReader objDR = objCmd.ExecuteR eader();
objDR.Read();
Response.Write( objDR["field"] + "<br>");
objConn.Close() ; }
</script> <p>Thus ends my query. </p>
</body>
</html> The code executes properly and produces the expected results, however its printing those results at the top of the page before any of the html. (Even though the code is sandwiched between html code) What am I doing wrong? :-) Thank You,
Brad
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David |
last post by:
I am retreiving information from a database and it works ok, but its
rather a lot and I like to limit each web page to 10 rows of data,
then put the next ten on a new web page, probably with a back|forward
buttons at the bottom.
Problem is I really not sure how to do this any would hoping someone
could throw me some advice!
Cheers!!
|
by: Robert |
last post by:
I have a php/mysql query working like so:
$Query = "SELECT * FROM $TableName WHERE name LIKE '%".$searchterm."%'
"
All I want to do now is sort them alphabetically. By using the above
current query, the results are listed in the order in which they were
placed in the database.
TIA
|
by: Francisco |
last post by:
I have this question:
I have a simple search to a db, something like:
"select description from games where year = '1990'"
suppose I get 300 results, I would like to display this in pages of 30
results per page, so I would use "limit 0, 30" for the first page.
But this way, I don't know how many results would I have if I didn't use
"limit".
So how do I know if I have more than one page to display?, the only way I
can thing is to do the...
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.
Now, the problem that I am...
|
by: Matt K. |
last post by:
Hi there,
I have a form in an Access project that contains a subform which
displays the results of a query of the style "select * from
where = #a certain date#". In the main part of the form
the user can change the date, which will force a requery in the
subform to bring up records from the date selected.
My question is this... The query in the subform is a very simple one,
with only three fields being returned. In the interest of...
| |
by: Joe |
last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource
(using Oracle ODBC drivers). After linking the tables in Access, I inspect
the data contained in the linked tables. For tables that involve a number
field as the primary key, the data is returned successfully. For tables
that involve a character field (e.g. CHAR(3) or VARCHAR(10)) as the primary
key, I have the correct number of rows returned, but the data displayed...
|
by: NasirMunir |
last post by:
I have created a table in access (copied from excel). Then I created a form which contains a text field and a list box. The text field is actually a look-up field, where a user can enter a searchable text and the results are displayed in the list box(the search is done on the table which I copied from excel). Everything works fine as I want.
The problem: I cannot copy the results from that list box to the excel sheet. It just copies the first...
|
by: Lloyd Harold |
last post by:
I'm very new to PHP and attempting to put together a simple script for
retrieving MySQL data of personal records.
The MySQL table I'm using consists of:
0: id
1: name
2: location (an integer relating to a separate table of locations).
3: details
|
by: chazzy69 |
last post by:
I having trouble displaying information i have retrieved from an mysql database,
i succesfully execute the SELECT query as shown below-
$sql = "SELECT PCODE,LOCALITY,STATE FROM `postcode` WHERE `Index` =1";
But when i try to display it i get errors saying basically -
"mysql_fetch_row(): supplied argument is not a valid MySQL result resource"
|
by: Nightcrawler |
last post by:
I have a website that does the following:
1. it accepts a keyword through a textbox in the UI
2. once the submit button is clicked it goes out and spiders a few
websites using the keyword supplied
3. it converts the returned html to xml
4. it uses LINQ to query the html page and stores the results in a
database table
5. it then pulls the results from the database using a LINQ query ad
displays them on a webpage
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |