Dim count As Int32
query = "SELECT * FROM table WHERE ID = " & txtID.text
Dim cmd As New SqlCommand(sql, cnn)
cmd.Connection.Open()
count = cmd.ExecuteNonQuery
if count >=1 then
sql = "update table SET name = " & txtName.text & " WHERE ID = " & txtID.text
else
sql = "Insert into table values(" & txtID.text &"," & txtName.text & ")"
end if
Date :
2019-02-22 17:02:23
By :
lamaka.tor
No. 2
Guest
IF EXISTS (SELECT * FROM table WHERE ID = 1)
--ถ้ามีข้อมูลแล้วให้อัพเดท
BEGIN
update table SET ...
END
ELSE
--ถ้ายังไม่มีข้อมูลให้ Insert
BEGIN
Insert into ...
END