forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule1.vb
96 lines (73 loc) · 2.21 KB
/
module1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Imports System.Linq
Module Module1
Sub Main()
Dim db As New Northwnd("...")
' This is InsertOnSubmit
' <Snippet1>
' Create a new Order object.
Dim ord As New Order With _
{.OrderID = 12000, _
.ShipCity = "Seattle", _
.OrderDate = DateTime.Now}
' Add the new object to the Orders collection.
db.Orders.InsertOnSubmit(ord)
' Submit the change to the database.
Try
db.SubmitChanges()
Catch e As Exception
Console.WriteLine(e)
' Make some adjustments.
' ...
' Try again.
db.SubmitChanges()
End Try
' </Snippet1>
End Sub
Sub methodUpdate()
' This is Update.
Dim db As New Northwnd("c:\northwnd.mdf")
' <Snippet2>
' Query the database for the row to be updated.
Dim ordQuery = _
From ord In db.Orders _
Where ord.OrderID = 11000 _
Select ord
' Execute the query, and change the column values
' you want to change.
For Each ord As Order In ordQuery
ord.ShipName = "Mariner"
ord.ShipVia = 2
' Insert any additional changes to column values.
Next
' Submit the changes to the database.
Try
db.SubmitChanges()
Catch e As Exception
Console.WriteLine(e)
' Make some adjustments.
' ...
' Try again
db.SubmitChanges()
End Try
' </Snippet2>
End Sub
Sub methodDelete()
Dim db As New Northwnd("c:\northwnd.mdf")
' <Snippet3>
' Query the database for the rows to be deleted.
Dim deleteOrderDetails = _
From details In db.OrderDetails() _
Where details.OrderID = 11000 _
Select details
For Each detail As OrderDetail In deleteOrderDetails
db.OrderDetails.DeleteOnSubmit(detail)
Next
Try
db.SubmitChanges()
Catch ex As Exception
Console.WriteLine(ex)
' Provide for exceptions
End Try
' </Snippet3>
End Sub
End Module