如何使用WebMatrix中的Razor连接到SQL Server数据库并检索数据?

时间:2014-02-15 07:24:00

标签: asp.net sql-server razor webmatrix

我正在 Asp.net 中使用 WebMatrix 开发网站。我已经下载并安装了 SQL Server 。现在我不知道如何在SQL Server中创建数据库以及如何使用Razor语法/方法连接到它。

2 个答案:

答案 0 :(得分:3)

WebMatrix很容易连接到SQL Server;有一个可以引导您的旧教程:Connecting to a SQL Server or MySQL Database in WebMatrix

关于在SQL Server中创建表,有关于如何完成此任务的书籍。简单的方法是使用SQL Server Management Studio。谷歌搜索我发现本教程可能有所帮助:Creating databases using SQL Server Management Studio Express

答案 1 :(得分:0)

如果您想在razer中工作并希望连接数据库并检索数据。

var db = Database.Open("Employee");
var dbCommand = "SELECT * FROM Movies WHERE ID = '1'"; // Select the name where id=1
var row = db.QuerySingle(dbCommand);
if(row != null) 
{
     var employee_name = row.Name;
}