473,398 Members | 2,343 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,398 software developers and data experts.

Hyperlink Search Results/SQL DB/BLOB Field/View PDF in Browser/Visual C#

8
Hi,

I am trying to create a "simple" application, of which, one of the functionalities is to be able to view a PDF Image (Invoice) held in a BLOB field on an SQL Database in the web browser.

As it stands, I have successfully created a form that asks the user to enter an Invoice Number and it pulls up the PDF Image from the BLOB in the SQL DB and displays it in the browser.

However, now what i'm trying to do is to create a form that asks the user for a Client number and then pulls up all the Invoice numbers that client currently has from the SQL DB. Upon displaying the list of Invoice Numbers, I would like these to be hyperlinked and, upon being clicked, directed to the corresponding PDF Image... but i'm stuck!!!

Here is the coding I have to pull up the actual PDF by entering the invoice number:

Expand|Select|Wrap|Line Numbers
  1.    protected void Button1_Click1(object sender, EventArgs e)
  2.     {
  3.          int GetInvdID;
  4.          GetInvdID = Convert.ToInt32(txtInvoice.Text);
  5.          byte[] data = null;
  6.  
  7.          using (SqlConnection con = new SqlConnection("server=serername;database=database_name;user id=username;password=password;"))
  8.          {
  9.              con.Open();
  10.  
  11.              string SqlStatement = "SELECT Invd_PDF_Image FROM Invoice_Details WHERE Invoice_Details.Invd_ID=";
  12.  
  13.              SqlCommand cmd = new SqlCommand(SqlStatement + GetInvdID, con);
  14.              SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  15.  
  16.              while (reader.Read())
  17.              {
  18.                   data = (byte[])reader[0];
  19.  
  20.              }
  21.           }
  22.  
  23.           HttpContext.Current.Response.ContentType = "application/pdf";
  24.           HttpContext.Current.Response.Clear();
  25.           HttpContext.Current.Response.BufferOutput = true;
  26.           HttpContext.Current.Response.BinaryWrite(data);
  27.  
  28.     }
The above works fine. bu tthis is what I have so far for trying to create a hyperlink to each corresponding PDF after entering the client number:

Expand|Select|Wrap|Line Numbers
  1.    protected void btnClientRef_Click(object sender, EventArgs e)
  2.     {
  3.         string GetClientRef;
  4.         GetClientRef = txtClientRef.Text;
  5.         byte[] data = null;
  6.  
  7.         using (SqlConnection con = new SqlConnection("server=server_name;database=database_name;user id=username;password=password;"))
  8.         {
  9.             con.Open();
  10.  
  11.             string SqlStatement1 = "SELECT TOP 10 Invd_Client_Ref,Invd_ID,Link_to_Client,Invoice_Client FROM Invoice_Details,Calls WHERE Invoice_Details.Invd_Client_Ref='" + GetClientRef + "'";
  12.  
  13.             SqlCommand cmd = new SqlCommand(SqlStatement1, con);
  14.             SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  15.  
  16.             while (reader.Read())
  17.             {
  18.                 Response.Write("Invoice Number: " + "<a href=" + "http://www.google.co.uk" + ">" + reader["Invd_ID"] + "</a> <br>");
  19.  
  20.             }

Where i've put 'Google' as the hyperlink, i'd like that to be hyperlinked to the corresponding PDF Image for the Invoice number that is displayed.


Sorry for the long post!

Can anyone help?

Thanks in advance.
Jan 10 '08 #1
10 2937
kenobewan
4,871 Expert 4TB
One way would be placing the link to where the image is displayed and using a querystring with the Invd_id to display the right image. HTH.
Jan 10 '08 #2
ESIS
8
One way would be placing the link to where the image is displayed and using a querystring with the Invd_id to display the right image. HTH.

Thanks for responding.

http://localhost:1053/PDF_Viewer/Default.aspx - that's the link that shows up in the browser when it is displayed...

how would i use a querystring in the context my coding? Could you possibly post some sample code for me? I'd really appreciate it.

Thanks again.
Jan 10 '08 #3
ESIS
8
Anyone? Please?

Thanks.
Jan 10 '08 #4
ESIS
8
One way would be placing the link to where the image is displayed and using a querystring with the Invd_id to display the right image. HTH.
Can anyone help with this, please?

I still have the same problem..

Thanks.
Jan 11 '08 #5
kenobewan
4,871 Expert 4TB
Have you tried:
Expand|Select|Wrap|Line Numbers
  1. Response.Write("Invoice Number: " + "<a href=" + "http://www.example.co.uk/default.aspx?link="+ reader["Invd_ID"]  + ">" + reader["Invd_ID"] + "</a> <br>");
  2.  
Jan 11 '08 #6
ESIS
8
Have you tried:
Expand|Select|Wrap|Line Numbers
  1. Response.Write("Invoice Number: " + "<a href=" + "http://www.example.co.uk/default.aspx?link="+ reader["Invd_ID"]  + ">" + reader["Invd_ID"] + "</a> <br>");
  2.  
Hi, yes. I already tried that, which worked fine in the sense that it assigns to each link it's own QueryString (Inv_ID) value.

However, I am still unable to use this value so that it directs the user to the corresponding PDF Image once the link is clicked...

Here is my code thus far:

Expand|Select|Wrap|Line Numbers
  1.  protected void btnClientRef_Click(object sender, EventArgs e)
  2.     {
  3.         // string GetClientRef;
  4.         string NewInvdID = Request.QueryString["QInvdID"];
  5.        // GetClientRef = txtClientRef.Text;
  6.  
  7.         using (SqlConnection con = new SqlConnection("server=server_name;database=database_name;user id=username;password=password;"))
  8.         {
  9.             con.Open();
  10.  
  11.             string SqlStatement1 = "SELECT TOP 10 Invd_Client_Ref,Invd_ID,Link_to_Client,Invoice_Client FROM Invoice_Details,Calls WHERE Invoice_Details.Invd_Client_Ref='" + GetClientRef + "'"; 
  12.  
  13.             SqlCommand cmd = new SqlCommand(SqlStatement1, con);
  14.             SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  15.  
  16.             while (reader.Read())
  17.             {
  18.  
  19.                 Response.Write("Invoice Number: " + "<a href=" + "http://localhost:1053/PDF_Viewer_Test/Default.aspx?QinvdID=" + reader["Invd_ID"] + ">" + reader["Invd_ID"] + "</a> <br>");
  20.  
  21.  
  22.             }
If you look at my initial post, the first chunk of code I posted allows the user to enter an Invoice Number and displays the corresponding PDF Image in the browser. This is what i'm trying to achieve; i.e. when the user clicks the hyperlinked invoice number, it should take it straight to the corresponding PDF Image.

Any ideas? I've been battling with it all afternoon, to no avail..

Thanks in advance.
Jan 11 '08 #7
ESIS
8
Still struggling over here...
Jan 11 '08 #8
ESIS
8
Anyone........................ ?
Jan 14 '08 #9
ESIS
8
Just to let you know, I have finally cracked after a whole day of battling with this morning and all day yesterday.

This is how I did it (code):

Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page
  2. {
  3.  
  4.     protected void Page_Load(object sender, EventArgs e)
  5.     {
  6.         if (this.Request.QueryString["QinvdID"] != null)
  7.             this.ViewPDF(Convert.ToInt32(this.Request.QueryString["QinvdID"]));
  8.     }
  9.  
  10.     protected void Button1_Click1(object sender, EventArgs e)
  11.     {
  12.         if (!string.IsNullOrEmpty(txtInvoice.Text))
  13.             this.ViewPDF(Convert.ToInt32(txtInvoice.Text));
  14.     }
  15.  
  16.     private void ViewPDF(int GetInvdID)
  17.     {
  18.  
  19.          byte[] data = null;
  20.  
  21.          using (SqlConnection con = new SqlConnection("server=server_name;database=database_name;user id=username;password=password;"))
  22.          {
  23.              con.Open();
  24.  
  25.              string SqlStatement = "SELECT Invd_PDF_Image FROM Invoice_Details WHERE Invoice_Details.Invd_ID=";
  26.  
  27.              SqlCommand cmd = new SqlCommand(SqlStatement + GetInvdID, con);
  28.              SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  29.  
  30.              if (reader.HasRows)
  31.              {
  32.                  reader.Read();
  33.  
  34.                  if (!reader.IsDBNull(0))
  35.                  {
  36.                     data = (byte[])reader[0];
  37.  
  38.                      HttpContext.Current.Response.ContentType = "application/pdf";
  39.                      HttpContext.Current.Response.Clear();
  40.                      HttpContext.Current.Response.BufferOutput = true;
  41.                      HttpContext.Current.Response.BinaryWrite(data);
  42.                  }
  43.                  else
  44.                  {
  45.                      Response.Write ("<script language=javascript>alert('" + "No PDF Image exists for Invoice Number " + GetInvdID + "'" + ")</script>");
  46.                  }
  47.              }
  48.         }
  49.     }
  50.  
  51.     protected void btnClientRef_Click(object sender, EventArgs e)
  52.     {
  53.         string GetClientRef;
  54.         GetClientRef = txtClientRef.Text;
  55.  
  56.         using (SqlConnection con = new SqlConnection("server=server_name;database=database_name;user id=username;password=password;"))
  57.         {
  58.             con.Open();
  59.  
  60.             string SqlStatement1 = "SELECT TOP 10 Invd_Client_Ref,Invd_ID,Link_to_Client,Invoice_Client FROM Invoice_Details,Calls WHERE Invoice_Details.Invd_Client_Ref='" + GetClientRef + "'";
  61.  
  62.             SqlCommand cmd = new SqlCommand(SqlStatement1, con);
  63.             SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  64.  
  65.             while (reader.Read())
  66.             {
  67.                 Response.Write("Invoice Number: " + "<a href=" + "http://localhost:1053/PDF_Viewer_Test/Default.aspx?QinvdID=" + reader["Invd_ID"] + ">" + reader["Invd_ID"] + "</a> <br>");
  68.             }   
  69.         }
  70.     }
  71. }
Thanks to all those who responded.

~ESIS
Jan 15 '08 #10
kenobewan
4,871 Expert 4TB
Well done! Programming can be like climbing a mountain, hours of pain and frustration for that brief exhiliration at the peak.

Respect to one of the best mountaineers of all time, Sir Edmund Hillary, who died on January 11th. Peace.
Jan 15 '08 #11

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

Similar topics

7
by: Randell D. | last post by:
Folks, I am working on a contact db using PHP and MySQL. My results so far outputs a slimed down version of records to the browser. I would like to implement a method whereby the user can...
1
by: Richard | last post by:
I have an on line search which produces a result, two lines of which appear in the results table so: mailto:UserId12345@mysite.com and http://www.mysite.com/image1.gif This looks totally...
4
by: Marco Krechting | last post by:
Hi All, Sorry but I have to create new message since it cannot find the old message to send a reply. Coming back to this hyperlink thing I will try to explain the real problem cause I think we...
5
by: Gamesetal | last post by:
Have '97 and am trying to create a query on the underlying Hyperlink field - ie if xxx then else ... Can't find a way to do this and would very much appreciate some kind help - thanks - John
10
by: david | last post by:
Hi, all: I need a help from you about DataGrid control. I created a DataGrid, dg, in design view of .NET visual Stadio and use the builder to add a Hyperlink column to dg. I want to try to assign...
2
by: BobLaughland | last post by:
Hi There, I need a control on my site that is a hyperlink style control, but it must, 1) Have a property that can hold where the hyperlink is pointing to. (e.g. like the NavigateUrl property...
5
by: NJonge01 | last post by:
Greetings, I've read some great advice on similar topics, just nothing matching exactly what I'm trying I'm pretty close I think on making this work, but note quite there. I want to print a...
1
by: rishiv | last post by:
Hi, I'm using MS Access 2002 SP3 & Visual Basic 6.3 on WinXP Home SP2. I have a table of condition data (5990 records) that relates to information stored in a proprietary application. The...
4
by: soulerrant | last post by:
Access 2003 SP2, Win XP I have a form that has Default View = Datasheet; allow Form View = No. Form opens in Datasheet view. The form has a text field with 'Is Hyperlink' set to Yes. When the...
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: 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
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
0
isladogs
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...

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.