ASP.NET MVC 連接 Model 後 Insert Record
Table Structure:
Table Name: Test
Table Column: Col1 (PK, nchar(10)), Col2 (nchar(10))
係 Controller 上加上 / 更改 |
Private _db As SoccerEntities Public Sub New() db = New SoccerEntities() End Sub Function Index(ByVal Input1 As String, ByVal Input2 As String) As ActionResult …… If Not (Input1 = "") And Not (Input2 = "") Then Dim TestRow As New Test TestRow.Col1 = Input1 TestRow.Col2 = Input2 _db.AddToTest(TestRow) _db.SaveChanges() End If …… Return View() End Function |
註: 連接既 Table 必須要有 PK (Primary Key) 及 PK 不能 重複 及 輸入 Blank Data