Writing Data to MSI Database

 ̄綄美尐妖づ 提交于 2019-12-25 05:23:11

问题


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?

Thanks


回答1:


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();
}


来源:https://stackoverflow.com/questions/14562231/writing-data-to-msi-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!