A Microsoft platform for building and publishing apps for Windows devices.
how can I delete the row in dataGrid using a checkbox to choose the row to delete and then press the delete button
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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)
{
}
A Microsoft platform for building and publishing apps for Windows devices.
how can I delete the row in dataGrid using a checkbox to choose the row to delete and then press the delete button
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"));
}
}
Hello
i'm changing the code.
I've changed the code I'm running to display the data for the datagrid
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