本地数据库,我需要一些例子 [英] Local database, I need some examples

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

问题描述

我正在将安装并在多台计算机上运行一个应用程序,我的目标是使安装了该应用程序,当用户使用app他的数据库来填充来自数据的空本地数据库文件应用程序。
你能为我提供了下面的例子:

I'm making an app that will be installed and run on multiple computers, my target is to make an empty local database file that is installed with the app and when user uses the app his database to be filled with the data from the app . can you provide me with the following examples :


  1. 什么,我需要做的,所以我的应用程序可以连接到本地数据库

  2. 如何从应用程序比如你会如何向数据库中添加变量执行一个查询以后的事

  1. what do I need to do so my app can connect to its local database
  2. how to execute a query with variables from the app for example how would you add to the database the following thing

String abc = "ABC";
String BBB = "Something longer than abc";


和等
:
我使用的创造了一个本地数据库,添加>新项目>本地数据库,所以如何将我连接到?很抱歉的愚蠢的问题..我从来没有使用数据库中的.NET

推荐答案

根据你也可以考虑SQL CE的需求。我敢肯定的是,如果你想使用,或您的要求的数据库,如果你是乌苏雷你会得到连接字符串等适当的和实际的例子。

Depending on the needs you could also consider Sql CE. I'm sure that if you specified the database you're thinking of using, or your requirements if you're usure you would get proper and real examples of connection strings etc.

编辑:这里是code为SQLCE / SQL精简

Here's code for SqlCe / Sql Compact

    public void ConnectListAndSaveSQLCompactExample()
    {
        // Create a connection to the file datafile.sdf in the program folder
        string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\datafile.sdf";
        SqlCeConnection connection = new SqlCeConnection("datasource=" + dbfile);

        // Read all rows from the table test_table into a dataset (note, the adapter automatically opens the connection)
        SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from test_table", connection);
        DataSet data = new DataSet();
        adapter.Fill(data);

        // Add a row to the test_table (assume that table consists of a text column)
        data.Tables[0].Rows.Add(new object[] { "New row added by code" });

        // Save data back to the databasefile
        adapter.Update(data);

        // Close 
        connection.Close();
    }

记住要添加一个引用System.Data.SqlServerCe

Remember to add a reference to System.Data.SqlServerCe

这篇关于本地数据库,我需要一些例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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