To do this you will need 2 methods. One that returns the correct object, and another to save the object once it has been modified like this:
Public Function GetSalariat(ByVal pcnp) As Salariat
Dim sConnection As String = "server=(local);Integrated Security=SSPI;database=Salarizare"
Dim c As New SqlConnection(sConnection)
Try
Dim ccnp As New SqlCommand
c.Open()
ccnp.Connection = c
ccnp.CommandText = "SELECT cnp, nume, prenume etc FROM salariati WHERE cnp = @cnp"
ccnp.Parameters.AddWithValue("@cnp", pcnp)
Dim drSalariats As SqlDataReader = ccnp.ExecuteReader()
Dim newSalariat As New Salariat()
While drSalariats.Read()
newSalariat.cnp = drSalariats.GetInt32(0)
newSalariat.nume = drSalariats.GetString(1)
newSalariat.prenume = drSalariats.GetString(2)
End While
Return newSalariat
Catch ex As SqlException
Throw ex
Finally
If c.State = ConnectionState.Open Then
c.Close()
End If
End Try
End Function
and to save:
Public Shared Function SaveSalariat(ByVal salariatToSave As Salariat) As Integer
Dim sCnnection As String = "server=(local);Integrated Security=SSPI;database=crossal"
Dim cnn As New SqlConnection With {.ConnectionString = sCnnection}
Try
Dim cmd As New SqlCommand
cnn.Open()
cmd.Connection = cnn
cmd.CommandText = "UPDATE tableName Set Nume = @Nume, PreNume = @Prenume, etc WHERE cnp = @Cnp"
cmd.Parameters.AddWithValue("@Nume", salariatToSave.nume)
cmd.Parameters.AddWithValue("@PreNume", salariatToSave.prenume)
Return cmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
If cnn.State = ConnectionState.Open Then
cnn.Close()
End If
End Try
End Function
Hope this helps