我有一个名为 的表studentlogs,它上面有列状态。当我在学生日志上完成插入记录时,我想使用一个if .. else语句。状态列只能有 3 个值1:2或3。
现在,我想在插入记录后执行以下操作:
if status="1" then
CALL SENDSMS()
ENDif
if status="2" then
msgbox("")
ENDif
if status="3" then
msgbox("")
当我处理列时我该怎么做?
要获取特定列中行的值,可以在行对象后使用括号并指定ColumnNameorColumnIndex属性来获取值。
此外,当有多个潜在价值时,您可以使用一个case语句,而不是很多ElseIf语句。
'declare local variables
Dim dr As DataRow
'create table
Dim studentLogs As New DataTable("StudentLogs")
'add columns
With studentLogs
.Columns.Add("Status", GetType(Integer))
.Columns.Add("OtherCol1", GetType(String))
End With
'add values
With studentLogs
dr = studentLogs.NewRow()
dr("Status") = 1
dr("OtherCol1") = "Joey"
studentLogs.Rows.Add(dr)
End With
For Each row As DataRow In studentLogs.Rows
Select Case row("Status")
Case 1
Call SENDSMS()
Case 2
MsgBox("2")
Exit For
Case 3
MsgBox("3")
End Select
Next