如何查找代码中是否出现where语句

时间:2015-03-06 16:08:45

标签: sql asp.net sql-server vb.net

我不知道如何在执行时查找代码中是否出现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()

2 个答案:

答案 0 :(得分:0)

ExecuteNonQuery返回受命令影响的行数。

对于UPDATEINSERTDELETE语句,返回值是受命令影响的行数。 (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