HELP!! I cant Update/edit the record in database??

Submitted by iannai18 on

pls help me! i cant update the record on my database her is my code

Dim conn As SqlConnection

        'connect to DB

        conn = New SqlConnection()

        conn.ConnectionString = "Data Source=IANRAMIREZ\SQLEXPRESS;Initial Catalog=Main;Integrated Security=True"

        'see if connection failed.

        Try

            conn.Open()

        Catch myerror As SqlException

            MsgBox("Error connecting to database!")

        End Try

        'sql query

        Dim myAdapter As New SqlDataAdapter

 

        Dim sqlquery = "SELECT * FROM Patient WHERE PatientID='" + Patient_IDTextBox.Text + "' "

        Dim myCommand As New SqlCommand()

        myCommand.Connection = conn

        myCommand.CommandText = sqlquery

        'start query

        myAdapter.SelectCommand = myCommand

        Dim myData As SqlDataReader

        myData = myCommand.ExecuteReader()

        'see if user exists

        If myData.HasRows = 1 Then

            conn.Close()

            conn.Open()

            Dim sample As New SqlDataAdapter

            sqlquery = "UPDATE Patient SET PatientID ='" & Trim(Patient_IDTextBox.Text) & "'," _

                                             & "Lastname='" & Trim(LastnameTextBox.Text) & "',Firstname='" & Trim(FirstnameTextBox.Text) & "', " _

                                            & "Middlename='" & Trim(MiddlenameTextBox.Text) & "',Address='" & Trim(AddressTextBox.Text) & "',Contacto='" & Trim(Contact_noTextBox.Text) & "', " _

                                            & "Birthdate='" & BirthdateDateTimePicker.Text & "',Age='" & Trim(AgeTextBox.Text) & "', " _

                                            & "CivilStatus='" & Trim(CivilStatusTextBox.Text) & "',Gender='" & Trim(GenderTextBox.Text) & "', " _

                                            & "Occupation='" & Trim(OccupationTextBox.Text) & "',Nationality='" & Trim(NationalityTextBox.Text) & "',Height='" & Trim(HeightTextBox.Text) & "',Weightl='" & Trim(WeightTextBox.Text) & "'" _

                                            & " where PatientID=" & PatientID & ""

 

            myCommand.Connection = conn

            myCommand.CommandText = sqlquery

 

            sample.SelectCommand = myCommand

            myData = myCommand.ExecuteReader()

 

            MsgBox("Information Added!")

            LastnameTextBox.Clear()

            FirstnameTextBox.Clear()

            Me.Show()

        Else

 

 

            MsgBox("Patients' Information already exist!", MsgBoxStyle.Exclamation)

 

 

        End If