Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim int_sql As Integer = -1
Dim str_sql As String = String.Empty
str_sql = "if exists (select tid,cname from test_table1 where tid=@tid) " & _
" BEGIN " & _
" update test_table1 set cname=@cname where tid=@tid " & _
" END"
Using conn As New SqlConnection("Server=.;uid=test;pwd=test;Database=school")
conn.Open()
Using command As SqlCommand = New SqlCommand(str_sql, conn)
command.Parameters.AddWithValue("@tid", "2")
command.Parameters.AddWithValue("@cname", "李四")
int_sql = command.ExecuteNonQuery() '回傳影響的筆數 -1
End Using
conn.Close()
End Using
Response.Write(int_sql)
End Sub
沒有留言:
張貼留言