我如何将文件插入Access数据库(在桌面应用程序中) [英] how can i insert files into access database (in desktop application)
本文介绍了我如何将文件插入Access数据库(在桌面应用程序中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了整个网站和文章,但找不到.
如何将文件插入Access数据库(在桌面应用程序中)
请有人帮我
i search whole site and articles but i can''t find it.
how can i insert files into access database (in desktop application)
please someone help me
推荐答案
您要做的就是将文件读入字节流中.
All you have to do is read the file into a byte stream
byte[] data = File.ReadAllBytes(path);
,然后使用参数化查询将其插入数据库.我建议您使用OleObject字段类型,否则您可能会发现自己空间不足.
then use a parametrized query to insert it to the database. I would recommend you use a OleObject field type as otherwise you may find yourself out of space.
using (OleDbConnection con = new OleDbConnection(strConnect))
{
con.Open();
using (OleDbCommand com = new OleDbCommand("INSERT INTO myTable (myFile) VALUES (@FILE)", con))
{
com.Parameters.AddWithValue("@FILE", data);
com.ExecuteNonQuery();
}
}
这篇关于我如何将文件插入Access数据库(在桌面应用程序中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文