将数据写入 MSI 数据库 [英] Writing Data to MSI Database

查看:28
本文介绍了将数据写入 MSI 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够更新一个二进制表,我这样做:

I need to be able to update a binary table and i do it like so:

View v = session.Database.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = '{0}'", binaryKeyName);

            v.Execute();

            var IsReadOnly = session.Database.IsReadOnly;

            Record r = v.Fetch();

            StreamReader reader = new StreamReader(r.GetStream("Data"));
            string text = reader.ReadToEnd();
            text = text.Replace(@"Test12345", "TTTest");

            byte[] byteArray = Encoding.ASCII.GetBytes(text);
            MemoryStream stream = new MemoryStream(byteArray);

一旦我有了流,我想更新数据库表.我该怎么做?

Once I have the stream I would like to update database table. How do i do it?

谢谢

推荐答案

WiX 附带的 dtf.chm 文档包含以下有关如何更新二进制表的示例:

The dtf.chm documentation, which comes with WiX, contains the following sample on how to update the binary table:

Database db = null;
View view = null;
Record rec = null;
try
{
    db = new Database("product.msi", DatabaseOpenMode.Direct);
    view = db.OpenView("UPDATE `Binary` SET `Data` = ? WHERE `Name` = '{0}'", binName))
    rec = new Record(1);
    rec.SetStream(1, binFile);
    view.Execute(rec);
    db.Commit();
}
finally
{
    if (rec != null) rec.Close();
    if (view != null) view.Close();
    if (db != null) db.Close();
}

这篇关于将数据写入 MSI 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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