Private Function SetTableValue() As Integer
Dim SqlCMD As SqlCommand
Dim SqlCN As New SqlConnection(Conn) Conn is your connection string
Dim recordsAffected As Integer, strSql As String
Try
strSql = "UPDATE myTable ...."
OR
strSql = "INSERT INTO myTable..."
If SqlCN.State = ConnectionState.Closed Then SqlCN.Open()
SqlCMD = New SqlCommand(strSql, SqlCN)
recordsAffected = SqlCMD.ExecuteNonQuery()
Catch
recordsAffected = -1
Finally
If SqlCN.State = ConnectionState.Open Then SqlCN.Close()
If Not SqlCMD Is Nothing Then SqlCMD.Dispose()
End Try
Return recordsAffected
End Function