ASP.NET ဝဘ်စာမျက်နှာများ - ဒေတာဘေ့စ်များ
ဤအခန်းသည် ဒေတာဘေ့စ်များနှင့် လုပ်ဆောင်ခြင်းအကြောင်းဖြစ်သည်။
ငါတို့ဘာလုပ်မလဲ။
ဤအခန်းတွင်ကျွန်ုပ်တို့သည်:
- ဒေတာဘေ့စ်တစ်ခုမှဒေတာစာရင်းသွင်းရန် ဝဘ်စာမျက်နှာတစ်ခုကို ဖန်တီးပါ။
Database မှ Data ကိုပြသခြင်း။
ဝဘ်စာမျက်နှာများနှင့်အတူ၊ သင်သည် ဒေတာဘေ့စ်တစ်ခုမှ ဒေတာများကို အလွယ်တကူ ပြသနိုင်သည်။
ရှိပြီးသားဒေတာဘေ့စ်တစ်ခုသို့ ချိတ်ဆက်နိုင်သည် သို့မဟုတ် ဒေတာဘေ့စ်အသစ်တစ်ခုကို အစမှစတင်ဖန်တီးနိုင်သည်။
ဤဥပမာတွင် ကျွန်ုပ်တို့သည် ရှိပြီးသား SQL Server Compact ဒေတာဘေ့စ်သို့ ချိတ်ဆက်ပါမည်။
ဖောက်သည်များ စာမျက်နှာကို ထည့်သွင်းခြင်း။
"DemoWebPages" ဖိုဒါတွင်၊ "Products.cshtml" အမည်ရှိ CSHTML ဖိုင်အသစ်တစ်ခုကို ဖန်တီးပါ။
ဖိုင်ရှိကုဒ်ကို အောက်ပါဥပမာမှ ကုဒ်ဖြင့် အစားထိုးပါ။
Products.cshtml
@{
var db = Database.Open("SmallBakery");
var selectQueryString = "SELECT * FROM Product ORDER BY Name";
}
<html>
<body>
<h1>Small Bakery Products</h1>
<table>
<tr>
<th>Id</th>
<th>Product</th>
<th>Description</th>
<th>Price</th>
</tr>
@foreach(var row in db.Query(selectQueryString))
{
<tr>
<td>@row.Id</td>
<td>@row.Name</td>
<td>@row.Description</td>
<td align="right">@row.Price</td>
</tr>
}
</table>
</body>
</html>
နမူနာရှင်းပြထားပါတယ်။
Database.Open( အမည် ) နည်းလမ်းသည် အဆင့်နှစ်ဆင့်ဖြင့် ဒေတာဘေ့စ်တစ်ခုသို့ ချိတ်ဆက်လိမ့်မည်-
ပထမဦးစွာ၊ ၎င်းသည် ဖိုင်အမည် တိုးချဲ့မှုမပါဘဲ အမည် ပါရာမီတာ နှင့် ကိုက်ညီသည့် ဒေတာဘေ့စ်အတွက် အပလီကေးရှင်း၏ App_Data ဖိုဒါကို ရှာဖွေသည် ။
မည်သည့်ဖိုင်ကိုမျှ ရှာမတွေ့ပါက၊ ၎င်းသည် အပလီကေးရှင်း၏ Web.config ဖိုင်တွင် "ချိတ်ဆက်မှုစာကြောင်း" ကို ရှာဖွေသည်။
(ချိတ်ဆက်မှုစာကြောင်းတစ်ခုတွင် ဒေတာဘေ့စ်တစ်ခုသို့ ချိတ်ဆက်ပုံနှင့်ပတ်သက်သည့် အချက်အလက် ပါရှိသည်။ ၎င်းတွင် ဖိုင်လမ်းကြောင်းတစ်ခု သို့မဟုတ် SQL ဒေတာဘေ့စ်အမည်၊ အသုံးပြုသူအမည်နှင့် စကားဝှက်အပြည့်အစုံပါရှိသည်)
ဤအဆင့်နှစ်ဆင့်ရှာဖွေမှုသည် အပလီကေးရှင်းကို ဒေသတွင်းဒေတာဘေ့စ်တစ်ခုဖြင့် စမ်းသပ်ရန်နှင့် ချိတ်ဆက်မှုစာကြောင်းကို အသုံးပြု၍ ဝဘ်အိမ်ရှင်တစ်ခုပေါ်တွင် အပလီကေးရှင်းကို လုပ်ဆောင်နိုင်စေသည်။
ASP.NET ဒေတာဘေ့စ် Object ရည်ညွှန်းချက်
Method | Description |
---|---|
Database.Execute(SQLstatement [, parameters]) | Executes SQLstatement (with optional parameters) such as INSERT, DELETE, or UPDATE and returns a count of affected records. |
Database.GetLastInsertId() | Returns the identity column from the most recently inserted row. |
Database.Open(filename) Database.Open(connectionStringName) | Opens either the specified database file or the database specified using a named connection string from the Web.config file. |
Database.OpenConnectionString(connectionString) | Opens a database using the connection string. (This contrasts with Database.Open, which uses a connection string name.) |
Database.Query(SQLstatement[, parameters]) | Queries the database using SQLstatement (optionally passing parameters) and returns the results as a collection. |
Database.QuerySingle(SQLstatement [, parameters]) | Executes SQLstatement (with optional parameters) and returns a single record. |
Database.QueryValue(SQLstatement [, parameters]) | Executes SQLstatement (with optional parameters) and returns a single value. |