如何使用sqlite3数据库部署visual studio 2012应用程序? [英] How to deploy visual studio 2012 application with sqlite3 database?

查看:95
本文介绍了如何使用sqlite3数据库部署visual studio 2012应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个使用数据库sqlite3的应用程序(winform)。我需要为应用程序创建.exe文件,并使用Visual Studio工具2012(InstallShield Limited Edition)将数据库安装到另一台机器上。数据库的路径(C:\ Users \A\Documents \\ myfirstdatabase.db3)那么如何使用数据库sqlite3部署应用程序?



I developed an application(winform) that use database sqlite3. I need to create the .exe file for the application and the database to install it on another machine using the Visual Studio tool 2012 ( InstallShield Limited Edition).the path of the database (C:\Users\A\Documents\myfirstdatabase.db3 ) so how deploy the application with the database sqlite3 ?

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using System.Data.SQLite;
using System.IO;

namespace mysqlite
{
    public partial class Form1 : RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        SQLiteConnection cn=new SQLiteConnection("data source=C:\\Users\\A\\Documents\\myfirstdatabase.db3");
        SQLiteCommand cmd = new SQLiteCommand();    

        private void Form1_Load(object sender, EventArgs e)        
        {      
            this.employeeTableAdapter.Fill(this.myfirstdatabase.db3DataSet.Employee);
            cn.Open();            
        }       

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                cmd.CommandText = "select from Employee";
                cmd.Connection = cn;      
                cmd.ExecuteNonQuery();

                this.employeeTableAdapter.Fill(this.myfirstdatabase.db3DataSet.Employee);
            }         
            catch 
            { 
                MessageBox.Show("you have an error"); 
            }  
        }
    }   
}

推荐答案

InstallShield LE是非常简单的工具提供设置部署的基本功能。您应该将数据库文件myfirstdatabase.db3添加到InstallShield LE项目中,它将放置在可执行文件所在的位置。现在,您可以在代码中使用相对路径来访问将驻留在可执行文件目录中的db文件,但是我通过将绝对路径保存到文本文件(system.txt)来完成此操作,然后始终从该路径实现文本文件,如果用户想要更改db文件的位置,他只需用system.txt中保存的现有路径替换路径
InstallShield LE is very simple tool providing the basic features of setup deployment. You should add the database file myfirstdatabase.db3 to your InstallShield LE project, it will be placed where executable resides. Now you can use relative path in your code to access the db file which will be residing in the executable directory, however I did this by saving the absolute path to a text file (system.txt) and then the path is always achieved from that text file, if user wants to change the location of db file he will just replace the path with the existing path saved in system.txt


这篇关于如何使用sqlite3数据库部署visual studio 2012应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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