通过Visual Studio创建数据库并管理与用C#编写的代码的交互 [英] Create a database through visual studio and manage the interaction with code written in c#

查看:217
本文介绍了通过Visual Studio创建数据库并管理与用C#编写的代码的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在C#中的项目遇到了一个问题,特别是数据库的创建以及与之的交互.我想要一些提示和指南.
从数据库类型开始:
-)假设我的数据量很小,应该创建哪种数据库? (我更喜欢在没有本地数据库和sql server的情况下工作)

让我们与项目建立联系:我应该如何将我的项目与数据库建立联系?有人可以给我一些指导和代码示例吗?


在此先感谢所有人

Alessio

Hi all,

I''ve a problem with my project in c#, specifically with the creation of a database and the interaction with it. I would like some tips and guidelines.
Starting with the kind of db:
-)premise that the bulk of my data is quite small, wich kind of database should I create? (I prefer work with no local database, and sql server)

Let''s connection with the project: how should i connect my project with the database? Could someone give me some guidelines, and some code''s example?


Thanks in advance to all

Alessio

推荐答案

如果您有SQL Server,请使用SQL Server数据库.除非您要分发应用程序,否则每个实例都将使用DB作为独立存储,在这种情况下,SQL Server有点过分.然后我会改用SQLCE或SQLite.
对于SQL Server数据库:
If you have SQL Server, then use an SQL server database. Unless you are going to be distributing your application, and each instance will use the DB as a standalone store, in which case SQL server is a bit overkill. Then I would use SQLCE or SQLite instead.
For SQL server databases:
using (SqlConnection con = new SqlConnection(strCon))
    {
    con.Open();
    string strcmd = "SELECT fileName FROM myTable WHERE iD=@ID";
    using (SqlCommand cmd = new SqlCommand(strcmd, con))
        {
        cmd.Parameters.AddWithValue("@ID", iD);
        using (SqlDataReader r = cmd.ExecuteReader())
            {
            while (r.Read())
                {
                Console.Write((string) r["fileName"]);
                }
            }
        }
    }


这篇关于通过Visual Studio创建数据库并管理与用C#编写的代码的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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