473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

8 New Member
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 2954
kenobewan
4,871 Recognized Expert Specialist
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 New Member
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 New Member
Anyone? Please?

Thanks.
Jan 10 '08 #4
ESIS
8 New Member
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 Recognized Expert Specialist
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 New Member
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 New Member
Still struggling over here...
Jan 11 '08 #8
ESIS
8 New Member
Anyone......... ............... ?
Jan 14 '08 #9
ESIS
8 New Member
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

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

Similar topics

7
4860
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 click on a text link which will then show the full record. I don't want to have hyperlinks with values incorporated in the link (thus, I don't want to...
1
1964
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 unelegant to me! (inelegant?) How do I replace these with image buttons one to say 'Send Email' and the other to say 'View Image' or something to that...
4
4380
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 are going in circles. I have a continous form with a hyperlink field on it. Normally when you click on a hyperlink field Access will follow the...
5
5852
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
1921
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 a column of URLs to this hyperlink column in programming way (ie., dynamically assignment). However, I can not find a way to continue doing it. ...
2
2799
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 in the asp:hyperlink control). 2) Also can call my own method when the user clicks on the link (e.g. like the Click event in the asp:linkbutton...
5
21182
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 report that basically displays photographs. the photographs are located on a web server viewable from my browser. I want to reference the URL and...
1
2685
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 primary key in my table (MyKey) is the same as the key used to find data in the other windows application (C:\Folder\My.exe). So, if I am looking at a...
4
1975
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 hyperlink field is clicked, a browser opens. If the browser is closed, all is good. However, the 'Back' button on the browser is enabled. When...
0
7499
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7689
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, 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. ...
1
7456
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7786
tracyyun
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...
0
5076
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...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
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...

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.