在Visual Studio中创建新数据库而无需安装SQL Server [英] Making new database in visual studio without installing SQL server
本文介绍了在Visual Studio中创建新数据库而无需安装SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
是否可以在VisualStudio中创建新数据库而无需安装SQlServer ???
怎么样通过代码???
Hi
IS it possible to make a new database in VisualStudio without installing SQlServer???
what about by code???
推荐答案
通过使用SqlCeEngine类和其中一种方法,可以在硬盘中创建数据库! :)
By using SqlCeEngine class and one of the methods, it is possible to create database in your hard drive! :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
using System.Data.Sql;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
SqlCeConnection Connection = new SqlCeConnection(@"Data Source=E:\Behnoud.sdf;");//string connStr = "Data Source = Test.sdf; Password = <password>";
SqlCeEngine en = new SqlCeEngine(@"Data Source=E:\Behnoud.sdf;");
en.CreateDatabase();
try
{
Connection.Open();
SqlCeCommand Command = Connection.CreateCommand();
Command.CommandText = "CREATE TABLE Test(SerialNumber bigint)";
Command.ExecuteNonQuery();
}
catch (SqlCeException ex)
{
Console.WriteLine(ex.Message); ;
}
finally
{
if (Connection.State == System.Data.ConnectionState.Open)
{
Connection.Close();
}
}
Console.ReadKey();
}
}
}
使用msaccess这样做...
使用此视频作为参考连接到Microsoft Visual Studio 2012中的Access数据库 [< a href =http://www.youtube.com/watch?v=5XxSbR7RH24target =_ blanktitle =新窗口> ^ ]
use msaccess to do so...
use this video for reference Connecting to an Access Database in Microsoft Visual Studio 2012[^]
这篇关于在Visual Studio中创建新数据库而无需安装SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文