WPF C# Delete...

How to pass a delete

Page 1 of 1

2 Replies - 3955 Views - Last Post: 13 April 2009 - 08:21 PM Rate Topic: -----

#1 neo_xaml  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-April 09

WPF C# Delete...

Posted 13 April 2009 - 02:02 PM

Hi,

I am new to WPF and in this example I am basically trying to add the following delete functionality.

DELETE FROM InspectorTime WHERE TimeID=@TimeID

Can anyone guide me? Txs

Here's the xaml code:
<dg:DataGrid.Columns>
<dg:DataGridTextColumn IsReadOnly="True" Header="" Binding="{Binding Path=TimeID}" Visibility="Hidden" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Route Priority" Binding="{Binding Path=RoutePriority}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Job Address" Binding="{Binding Path=JobAddress}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Permit #" Binding="{Binding Path=PermitNumber}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Inspection Type" Binding="{Binding Path=TimeOptionEntry}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Start Time" Binding="{Binding Path=StartTime}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="End Time" Binding="{Binding Path=EndTime}" MinWidth="100" />
<dg:DataGridTemplateColumn Header="Void" Visibility="Visible" MinWidth="50" MaxWidth="50" >
<dg:DataGridTemplateColumn.
CellTemplate>
<DataTemplate>
<Button Content="Void" Foreground="Black" FontSize="12" VerticalAlignment="Center" MaxWidth="50" Click="VoidButton_Click" Tag="{Binding Path=TimeID}" Uid="{Binding Path=TimeID}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

</dg:DataGrid.Columns>


Here's the ref code:

private void VoidButton_Click(object sender, RoutedEventArgs e)
{

if (MessageBox.Show("Are you sure you want to void the time?", "Void Inspection", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
// delete SQL query
{
try
{

MessageBox.Show("Information Updated.", "Update");
}
catch (Exception oEx)
{
MessageBox.Show("Information not Updated.", "Update");
}

}
}

Txs

Is This A Good Question/Topic? 0
  • +

Replies To: WPF C# Delete...

#2 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: WPF C# Delete...

Posted 13 April 2009 - 03:23 PM

Please place that code between code tags.
Was This Post Helpful? 0
  • +
  • -

#3 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: WPF C# Delete...

Posted 13 April 2009 - 08:21 PM

View Postneo_xaml, on 13 Apr, 2009 - 01:02 PM, said:

Hi,

I am new to WPF and in this example I am basically trying to add the following delete functionality.

DELETE FROM InspectorTime WHERE TimeID=@TimeID

Can anyone guide me? Txs

Here's the xaml code:
<dg:DataGrid.Columns>
<dg:DataGridTextColumn IsReadOnly="True" Header="" Binding="{Binding Path=TimeID}" Visibility="Hidden" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Route Priority" Binding="{Binding Path=RoutePriority}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Job Address" Binding="{Binding Path=JobAddress}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Permit #" Binding="{Binding Path=PermitNumber}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Inspection Type" Binding="{Binding Path=TimeOptionEntry}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="Start Time" Binding="{Binding Path=StartTime}" MinWidth="100" />
<dg:DataGridTextColumn IsReadOnly="True" Header="End Time" Binding="{Binding Path=EndTime}" MinWidth="100" />
<dg:DataGridTemplateColumn Header="Void" Visibility="Visible" MinWidth="50" MaxWidth="50" >
<dg:DataGridTemplateColumn.
CellTemplate>
<DataTemplate>
<Button Content="Void" Foreground="Black" FontSize="12" VerticalAlignment="Center" MaxWidth="50" Click="VoidButton_Click" Tag="{Binding Path=TimeID}" Uid="{Binding Path=TimeID}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

</dg:DataGrid.Columns>


Here's the ref code:

private void VoidButton_Click(object sender, RoutedEventArgs e)
{

if (MessageBox.Show("Are you sure you want to void the time?", "Void Inspection", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
// delete SQL query
{
try
{

MessageBox.Show("Information Updated.", "Update");
}
catch (Exception oEx)
{
MessageBox.Show("Information not Updated.", "Update");
}

}
}

Txs

Quote

What is the Database are you using? What is the connection driver you used? There are many connection string in C# and to delete, insert and update a record. I will show you an example in deleting a record.

SqlCommand delete = null;

			try
			{
				delete = new SqlCommand("delete from maintenance where username = '" + txtUsername.Text + "'", connect);
				delete.ExecuteNonQuery();

				lblError.Text = "One record deleted.";
				lblError.Visible = true;
			}
			catch (Exception ex)
			{
				lblError.Text = ex.Message;
				lblError.Visible = true;
			}
			finally
			{
				if (delete != null)
				{
					delete.Dispose();
					delete = null;
				}

				connect.Close();

				
			}


Take note that SqlCommand is depend on the connection type because there is also OdbcCommand and MySqlCommand.

This post has been edited by newProgram: 13 April 2009 - 08:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1