Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more: , +
I need to pass a varchar field in a table to my windows form and change it on a button click to pdf file as output,my requirement is due to the extensive varchar size in the field so i need it to convert it into pdf
Posted
Updated 8-Apr-15 22:09pm
v3
Comments
OriginalGriff 9-Apr-15 3:08am    
STOP SHOUTING!

Using all upper case on the web is SHOUTING and considered rude.
Varun Das 9-Apr-15 3:56am    
sorry for my typing style ,could reply for my query if possible i'm kind of held up

Try:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT myPDFData FROM myTable", con))
        {
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                string myPDFData = (string) reader["myPDFData"];
                File.WriteAllText(@"D:\Temp\mydata.PDF", myPDFData);
                }
            }
        }
    }
 
Share this answer
 
Comments
Varun Das 9-Apr-15 3:52am    
HI,
BUT THE FIELD IS IN BINARY FORMAT AND THAT TOO IT IS HUGE VALUE,SO I NEED TO READ THAT PARTICULAR FIELD FROM TABLE AND TRANSFER THE VALUE AS TEXT FILE IN A PDF FOR VIEWING ,IF THE VALUE CONVERTED IS ACCURATE WITH THE HELP OF A BUTTON CLICK IN WINDOWS FORM
OriginalGriff 9-Apr-15 4:11am    
STOP SHOUTING.
I will have nothing to do with you if you are going to just be rude.
Varun Das 9-Apr-15 4:20am    
i'm sorry if i'm being rude
private void button1_Click_1(object sender, EventArgs e)
{

string s = "";
byte[] bytes = Convert.FromBase64String(s);



System.IO.FileStream stream =
new FileStream(@"D:\file.pdf", FileMode.CreateNew);
System.IO.BinaryWriter writer =
new BinaryWriter(stream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900