elszeus
elszeus

Reputation: 131

Update SqlCommand- Does not update in Database

this doesn't update in my database table. Have I over-looked something?

The values are in the textboxes fine. No errors show, weird.

          using (SqlConnection connection = new SqlConnection(@"Data Source = UKMAN1NB10038\SQLEXPRESS; Initial Catalog = TheVets; Integrated Security = True"))
        {
            SqlCommand command = new SqlCommand("UPDATE OwnerTable SET Owner_Fname =@OwnerFname , Owner_Lname = @OwnerLname, Owner_HouseNo = @OwnerHouse, Owner_Street = @OwnerStreet, Owner_County = @OwnerCounty, Owner_PostCode = @OwnerPost, Owner_Tele = @OwnerTele, Owner_Email = @OwnerEmail WHERE Owner_ID = '" + CB_EDIT_OWNER.SelectedText + "'", connection);

            command.CommandType = CommandType.Text;
            command.Connection = connection;



            command.Parameters.AddWithValue("@OwnerFname", TXT_EDIT_FNAME.Text);
            command.Parameters.AddWithValue("@OwnerLname", TXT_EDIT_LNAME.Text);
            command.Parameters.AddWithValue("@OwnerHouse", TXT_EDIT_HOUSE.Text);
            command.Parameters.AddWithValue("@OwnerStreet", TXT_EDIT_STREET.Text);
            command.Parameters.AddWithValue("@OwnerCounty", TXT_EDIT_COUNTY.Text);
            command.Parameters.AddWithValue("@OwnerPost", TXT_EDIT_POSTCODE.Text);
            command.Parameters.AddWithValue("@OwnerTele", TXT_EDIT_TELE.Text);
            command.Parameters.AddWithValue("@OwnerEmail", TXT_EDIT_EMAIL.Text);

            connection.Open();
            command.ExecuteNonQuery();

            connection.Close();
        }
    }

Upvotes: 1

Views: 78

Answers (1)

WhatsThePoint
WhatsThePoint

Reputation: 3635

You need to use SelectedItem not SelectedText on the combobox

Replace CB_EDIT_OWNER.SelectedText with:

CB_EDIT_OWNER.SelectedItem

Then this should work.

Upvotes: 3

Related Questions