如何从c#中的dox文件和pdf文件中的数据库中获取数据 [英] how to fetch data from database in dox file and pdf file in c#

查看:286
本文介绍了如何从c#中的dox文件和pdf文件中的数据库中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从dox文件和pdf文件中的数据库中获取数据c#

how to fetch data from database in dox file and pdf file in c#

推荐答案

存储在数据库中的数据不具有内在的DOX或PDF格式 - 如就SQL(或任何数据库)而言,它只是数据:二进制或基于字符 - 并且它不考虑内容。因此,获取它与任何其他基于二进制(或文本)的数据相同:

Data stored in a database has not "intrinsic" DOX or PDF format - as far as SQL (or any DB) is concerned it is just data: either binary or character based - and it takes no account of the content. As a result, fetch it is just the same as you would for any other binary (or text) based data:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT textData, binaryData FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                string text = (string) reader["textDats"];
                byte[] data = (byte[]) reader["binaryData"];
                ...
                }
            }
        }
    }

一旦你把它作为字符串或字节数组,你可以考虑内部格式并将其保存为正确的文件类型,或者执行其他任何操作。



在Windows中,文件上的扩展名只控制应用程序将尝试打开它,以及他们如何尝试处理内容:您可以将Excel数据写入.CS文件,VS将尝试打开它 - 它会失败,但它会尝试。如果您希望数据可以通过PDF阅读器打开,请将其保存在扩展名为.PDF的文件中(并希望它是您在DB中保存的PDF数据)。

Once you have it as a string or array of bytes, you can then consider the internal format and save it as the proper file type, or do whatever else you need to with it.

In Windows, the extension on a file just controls what applications will try to open it, and how they try to process the content: you can write Excel data to a .CS file and VS will try to open it - it'll fail, but it'll try. If you want your data openable by a PDF reader, then save it in a file with a .PDF extension (and hope it was PDF data you saved in the DB to start with).


这篇关于如何从c#中的dox文件和pdf文件中的数据库中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆