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();
}
}
CB_EDIT_OWNER.SelectedText? why is that not a parameter too? (It is very possible that owner_id not being a parameter is the source of your problem)commandshould also be wrapped in using() { }, like the connection.CB_EDIT_OWNER.SelectedTextreturnsSystem.ComponentModel.Component. If nothing is subscribing to it'sDisposedevent there is no need to dispose it. It falls in to the same category asDataTableorTask, both of those are disposable too but you don't need to dispose of them either normally.