我不知道如何在执行时查找代码中是否出现where
语句:
Dim cmd2 As SqlCommand = New SqlCommand("
UPDATE ShTb
SET Email=@EmailAddress,
Temp=@temp,
TEL=@telnum,
TempTime=@temptime
WHERE ShID=@SharjID", con1)
cmd2.Parameters.AddWithValue("@EmailAddress", EmailAddress)
cmd2.Parameters.AddWithValue("@SharjID", SharjID)
cmd2.Parameters.AddWithValue("@temp", temp)
cmd2.Parameters.AddWithValue("@telnum", telnum)
cmd2.Parameters.AddWithValue("@temptime", temptime)
con1.Open()
cmd2.ExecuteNonQuery()
con1.Close()
答案 0 :(得分:0)
ExecuteNonQuery返回受命令影响的行数。
对于UPDATE
,INSERT
和DELETE
语句,返回值是受命令影响的行数。 (MSDN)
dim r1 as int
r1=cmd2.ExecuteNonQuery()
If r1 > 0 --one, or more rows were affected....
答案 1 :(得分:0)
我假设您想知道更新是否有任何行受影响。
您可以通过检查ExecuteNonQuery
Dim rowsEffected = cmd2.ExecuteNonQuery()
if rowsEffected > 0 Then
'One or more rows were changed
End if