简体   繁体   English

将创建的PDF保存到MySQL数据库C#

[英]Save created PDF to MySQL database C#

I want to be able to store newly created PDF in a BLOB field in my MySQL database. 我希望能够在MySQL数据库的BLOB字段中存储新创建的PDF。 This is the code I have so far but it saves to local disk instead: 这是我到目前为止的代码,但是将其保存到本地磁盘:

        string fileName = employeeNo.ToString();
        MemoryStream ms = new MemoryStream();
        byte[] bits = new byte[0];

        Document doc = new Document();
        PdfWriter writer = PdfWriter.GetInstance(doc, ms);
        doc.Open();
        iTextSharp.text.Rectangle rec2 = new iTextSharp.text.Rectangle(PageSize.A4);
        doc.Add(new Paragraph(textBox2.Text));
        doc.Add(new Paragraph(textBox1.Text));
        doc.Close();
        bits.ToArray();

How could I adapt this so that it can be inserted into my database instead? 我该如何调整它以便可以将其插入数据库? The file would then be passed into the insert statement as below: 然后,该文件将被传递到insert语句中,如下所示:

myCmd.Parameters.AddWithValue("@feedbackComments", bits);

Instead of a FileStream use a MemoryStream and extract the byte array with ToArray() after closing the doc. 在关闭文档后,使用MemoryStream代替FileStream并使用ToArray()提取字节数组。

Use the byte array to populate the table. 使用字节数组填充表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM