I have a DataGrid but when I point the line I can not delete the record from delete button. what I want to know is how to delete the record from the table when I choose it to be deleted the line
Remove Datagrid row in Sql Server uwp c#
Javier R
211
Reputation points
Remove Datagrid row in Sql Server uwp c#
const string PetDeleteQuery = "Delete FROM PetTable where idPet = 1";
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = PetDeleteQuery;
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
}
catch(Exception ex)
{
}
5 answers
Sort by: Most helpful
-
-
Javier R 211 Reputation points
2021-07-01T18:29:23.497+00:00 I've changed the code I'm running to display the data for the datagrid
-
Javier R 211 Reputation points
2021-07-09T18:05:22.627+00:00 Hello
i'm changing the code.
-
Javier R 211 Reputation points
2021-07-13T17:53:26.547+00:00 public async void bind() { pets = new ObservableCollection<PetTable>(); try { const string GetPetTableQuery = "SELECT * FROM PetTable"; using (SqlConnection conn = new SqlConnection(connectionString)) { await conn.OpenAsync(); if (conn.State == System.Data.ConnectionState.Open) { using (SqlCommand cmd = new SqlCommand(GetPetTableQuery, conn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { PetTable pet = new PetTable(); BitmapImage map = new BitmapImage(); byte[] bytes = (byte[])reader["Picture"]; var stream = new InMemoryRandomAccessStream(); await stream.WriteAsync(bytes.AsBuffer()); stream.Seek(0); await map.SetSourceAsync(stream); pet.Picture = map; pet.PetType = (string)reader["Type"]; pet.DuoDate = (DateTime)reader["Date"]; pet.PetName = (string)reader["Name"]; pet.PetRace = (string)reader["Race"]; pet.PetColor = (string)reader["Color"]; pet.PetChip = (string)reader["Chip"]; pet.PetGender = (string)reader["Gender"]; pet.PetSterile = (string)reader["Sterile"]; pets.Add(pet); } } } } } } } catch (Exception ex) { var Msg = new MessageDialog("Exeception:" + ex.Message); Msg.Commands.Add(new UICommand("Close")); } }
-
Javier R 211 Reputation points
2021-11-10T16:44:00.133+00:00 how can I delete the row in dataGrid using a checkbox to choose the row to delete and then press the delete button