473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Iterate through datareader & add hyperlink

Hi What is the best way to iterate through a datareader? I only seem to be getting one record back when there should be two, I need to print all records from SQL statement out and add a hyperlink to it.
Thanks in advance code so far below:




protected void btnSearch_Click(object sender, EventArgs e)
{
hpResult.Text = "";
hpResult.NavigateUrl = "";
OracleConnection con = new OracleConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["NewExpedioDevString"].ConnectionString;
// string cmdQuery = "SELECT R_EXPEDIOREFERENCE,R_CUSTOMERREFERENCE,R_TITLE, R_REQUESTSTATUS, R_REQUESTTASK, CR_DOPID FROM aradmin.exp__request WHERE (r_source = 'KANA' AND R_EXPEDIOREFERENCE LIKE '" + txtExRef.Text + "')";
string cmdQuery = "SELECT R_EXPEDIOREFERENCE,R_CUSTOMERREFERENCE,R_TITLE, R_REQUESTSTATUS, R_REQUESTTASK, CR_DOPID FROM aradmin.exp__request WHERE (r_source = 'KANA' AND (R_EXPEDIOREFERENCE='VCC00000560' OR R_EXPEDIOREFERENCE='VCC00000569'))";
OracleCommand cmd = new OracleCommand(cmdQuery);
try
{
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
OracleDataReader reader = cmd.ExecuteReader();
lblResult.Text = "No Results Found!";
while (reader.Read())
{
Response.Write(reader["R_EXPEDIOREFERENCE"].ToString() + "</br>");
hpResult.Text = reader["R_EXPEDIOREFERENCE"].ToString();
hpResult.NavigateUrl = "default.aspx?ERID=" + reader["R_EXPEDIOREFERENCE"].ToString();
lblResult.Text = "";
pnlSearchResults.Controls.Add(hpResult);
pnlSearchResults.Visible = true;

}

}

catch (Exception ex)
{
lblResult.Text = ex.Message;
}

finally
{
cmd.Dispose();
con.Close();
con.Dispose();
}


}
Oct 1 '07 #1
6 1861
Plater
7,872 Expert 4TB
What you have seems like it should work. Although if there was more then one record, your link thing looks like it will just overwrite itself.
Are you sure you should be getting more then one record back?
Have you executed your exact query string in an sql window to see what the real results are?
Oct 1 '07 #2
yeah definitely 2 records, made sure so I knew what I should expect back.
I have now decided to bind the sql to a datagrid instead and use teh hyperlink field which is working but looks messy as I can;t seem to get rid of the automatically generated header texts it creates (I have added some bound fields with tidy header texts to replace the actual column names bit they just appear in addition to the actual column names :O( an advice?
thanks for such a quick response.Debs
Oct 1 '07 #3
Plater
7,872 Expert 4TB
Well in your sql query, remove that poorly named columns or cast them as a better named column.

Such as with:
Expand|Select|Wrap|Line Numbers
  1. SELECT id, fname, lname, username FROM peopletable;
  2.  
could be:
Expand|Select|Wrap|Line Numbers
  1. SELECT id as [Person ID], fname as [First Name], lname as [Last Name], username as [Username] FROM peopletable;
  2.  
Oct 1 '07 #4
Brilliant thank you !
sorry to ask seemingly stupid questions but i'm relatively new to all this! thanks
again
Debs
Oct 1 '07 #5
Keep getting ORA-00923: FROM keyword not found where expected when I put in the aliases....

string cmdQuery = "SELECT R_EXPEDIOREFERENCE AS [EXPEDIOREF],R_CUSTOMERREFERENCE AS [CUSTOMERREF],R_TITLE AS [TITLE], R_REQUESTSTATUSAS [STATUS], R_REQUESTTASK AS [TASK], CR_DOPID AS [CRDOPID] FROM aradmin.exp__request WHERE (r_source = 'KANA' AND (R_EXPEDIOREFERENCE='VCC00000560' OR R_EXPEDIOREFERENCE='VCC00000569'))";

can you see anything wrong with this?
(I tried it using the aliases in the where clause too but same result)
Oct 1 '07 #6
Plater
7,872 Expert 4TB
Hmm oracle's SQL may not support using the [ ] brackets or using the AS keyword. (I should have paid more attention to which DB type you were using).

You could pop over to the oracle section and check out, because the SQL looks good enough to my eyes.
Oct 1 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and...
2
by: P. Mellerin | last post by:
Hello, I have been searching online for a whole day and couldn't find an answer for this. I have this hyperlink server control: ...
2
by: martin | last post by:
hi, I am using vb.net. I have wrote a data access class and one of my methods returns a dataset. I would like to iterate through this, although this is proving problematic for me. Can...
1
by: D. Shane Fowlkes | last post by:
Hello All. I keep asking for help with this on the www.asp.net forums and nobody seems to be able to help. What I'm trying to accomplish is very simple. I simply want to create a Hyperlink...
6
by: FoundThisOnline | last post by:
I have been searching online for a whole day and couldn't find an answer for this. I have this hyperlink server control: ------------------------------------------------ <asp:HyperLink...
7
by: D Miller | last post by:
Here is today's challange... I would like to scan though the properties of the class and take actions based on the name of the property. Something Like Dim Work as new Test
4
by: Mike | last post by:
Hello, How can I get Random data from Dataset or datareader THanks -- Regads, Rochdi
2
by: rodchar | last post by:
hey all, is it possible to iterate thru a datareader and change the value of certain fields before binding to control? If so, can someone please so me some basic syntax for this? thanks,...
0
by: mahaq | last post by:
Hi Guys, I like to know if there is any better solution to this issue. I am a front end developer using CSS and asp.net technologies I have a .net page and I am using an external CSS file....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.