简体   繁体   中英

How to connect to SQL Server database and retrieve data using Razor in WebMatrix?

I am developing a website using WebMatrix in Asp.net . I have downloaded and installed SQL Server . Now I don't know how to create a database in SQL Server and how to connect to it using Razor Syntax/Method.

WebMatrix is easy to connect to SQL Server; there is an old tutorial that can lead you: Connecting to a SQL Server or MySQL Database in WebMatrix .

With regard to create a table in SQL Server, there are books on how to accomplish this task. The easy way is to use SQL Server Management Studio. Googling I have found this tutorial that maybe could help: Creating databases using SQL Server Management Studio Express .

If you want to work in razer and want to connect with data base and retrieve data.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM