I would like to update a table and it will only update if the record is found else a new record will be inserted into the table. I am not getting the results that i want with the code below. what other way can do to achieve the same result ?
Eg: weekid 3 is not found in the table, there for a new record will be inserted into the table.
Eg: weekid 3 is not found in the table, there for a new record will be inserted into the table.
VB.NET:
cmd.Connection = conn
conn.Open()
Try
''Query to add info into table.
cmd.CommandText = "UPDATE WeekNo SET weekstart = '080211', weekend = '080217' WHERE weekid = 3"
cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
cmd.CommandText = "INSERT INTO WeekNo(weekid, weekstart, weekend) VALUES('3','080211','080217')"
cmd.ExecuteNonQuery()
End Try