Silverlight / WPF - Delete Command

Asked By David on 31-Dec-10 05:41 AM
Hi

I am trying to use a delete command from Dataset to delete 1 row at a time and the main part of the row is COURSEName.
The code below from configured DataSet does not delete any rows at all.


DELETE FROM COURSE
WHERE   (Prikey3 = ?) AND (? = 1 AND [Date Played] IS NULL OR
            [Date Played] = ?) AND (? = 1 AND COURSEName IS NULL OR
            COURSEName = ?) AND (? = 1 AND H1PAR IS NULL OR
            H1PAR = ?) AND (? = 1 AND H2PAR IS NULL OR

If I change it to the  show the code below it deletes all records

DELETE FROM COURSE

Please help I have been stuck on this for months

David
anil soni replied to David on 31-Dec-10 05:54 AM
You can delete a single record at time using follwing quries

SET ROWCOUNT 1
DELETE FROM COURSE
David replied to anil soni on 31-Dec-10 11:41 AM
Hi Anil

Thanks for the quick reply
I have tried but it did not work it kept saying

Error in table name or view name in DELETE clause.
Unable to parse query text.


Thanks

David
anil soni replied to David on 31-Dec-10 01:17 PM
strange!!!
try using
SET ROWCOUNT 1
DELETE FROM [COURSE]
David replied to anil soni on 31-Dec-10 02:15 PM
Hi Anil
It has not worked.

Do I need to put any filter in query builder?
And do I need to have all the table in the columns

This is the error I now get
Error in table name or view name in DELETE clause.
Unable to parse query text.

Thanks

David
anil soni replied to David on 31-Dec-10 02:20 PM
which database server you are using in your application?
David replied to anil soni on 31-Dec-10 02:24 PM
Hi Anil

I am using a Access Data-base on my Server explorer and then Datasets & Tableadapters.
The Delete command is from the Dataset-tableadapter
This is all in Visual Studio 2008 Xaml etc

Thanks

David
anil soni replied to David on 31-Dec-10 03:42 PM
ohhh i thought you are sql server and gave you solution for that anyways you can delete a particular record if you have primary key in your table else you have to give condition whcih  matches only a single record in order to delete single record.
David replied to anil soni on 01-Jan-11 04:46 PM

Hi Anil

I have a primary key called Prikey3


DELETE FROM COURSE
WHERE   (Prikey3 = ?) AND (? = 1 AND [Date Played] IS NULL OR
      [Date Played] = ?) AND (? = 1 AND COURSEName IS NULL OR
      COURSEName = ?) AND (? = 1 AND H1PAR IS NULL OR
      H1PAR = ?) AND (? = 1 AND H2PAR IS NULL OR

Please how do I change the Criteria to make it work

DELETE FROM COURSE
WHERE   (Prikey3 = ?)   This does not delete any


DELETE FROM COURSE   This deletes all rows


I am using Dataset-Tableadapter-query builder in Visual Studio 2008


Thanks

David

help
Hi, I have a DataSet with 4 rows. I use .Delete command to delete a row from it. I use .Count to get the number of remaining rows - still anyone seen this kind of behaviour? Thanks a lot in advance DG C# Discussions DataRow.Delete (1) DataSet.Delete (1) DataRow (1) AcceptChanges (1) Delete (1) RowState (1) DataSet (1) Discrepancies (1) Read
Delete button deletes data rows but exit xaml sheet and return to it and deleted rows Where are the data rows coming from? Is this WPF or Silverlight? How did the delete button get there, and what code does it run? This is basic posting netiquette - you to actually be able to help. Sorry Peter I am new to WPF & XAML The delete button was made from following the Beth Massi video on Data input sheet and information back. It is not deleteing from the Data-base I assume.I am using a DataSet & Tableadapter Private Sub btndelete_Click( ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs view.CurrentPosition > 1 Then Dim row = CType ( Me .view.CurrentItem, System.Data.DataRowView).Row row.Delete() End If End Sub Thanks David keywords: RoutedEventArgs, DataRowView, Silverlight, Silverlight WPF, XAML, WPF, Delete, Click, rows description: delete command Delete button deletes data rows but exit xaml sheet and
12 08:02 PM The following is the code I used for Update method, Insert command and Update command are working, but delete command is not working . I am supplying a changed datatable to it. MySqlDataAdapter da = new MySqlDataAdapter da.SelectCommand = new MySqlCommand ( "SELECT Itemtypeid, ItemType, CreatedBy, CreatedDate FROM ItemTypeMaster" , _conn); DataSet ds = new DataSet (); _conn.Open(); da.Fill(ds); da.InsertCommand = new MySqlCommand ( "Insert into ItemTypeMaster (ItemType, CreatedBy, CreatedDate) values (@ItemType, @CreatedBy, @CreatedDate)" , _conn); da.DeleteCommand = new MySqlCommand ( "Delete from ItemTypeMaster where ItemTypeId = @ItemTypeId" , _conn); da.UpdateCommand = new MySqlCommand ( "Update ItemTypeMaster set ItemType = @ItemType Add(ItemType); da.DeleteCommand.Parameters.Add(ItemTypeId); da.Update(dt); _conn.Close(); Make sure the delete command works same as the command you are having in mysql engine. . I am not
Hi, I'm just beginning my VS.NET 2005 adventure in C#, so maybe I'm missing something obvious. . . I created a dataset containing 3 tables, one "main" table and two lookup tables connected by a relation to the main table. Only for one of the lookup tables the wizzard generated update and delete commands. For the others only the select and insert commands are generated. Even when I these tables adapters, choose "configure" and step through the wizzard with option "generate insert, update, delete statements" under "Advanced options" set, after clicking "Finish" I still have no update and delete. So why does it work for one of the lookup tables but not for the other two in my dataset? Any hint for me? TIA, Stefan P.S.: my backend DB is Oracle10g i case tweak ERwin to generate the correct DDL script. Thanks anyway, Stefan keywords: HOWTO:, generate, update / delete, command, using, data, adapter, wizzard? description: Hi, I'm just beginning my VS.NET 2005
name ASP.NET 28-Oct-12 07:48 PM c#. Hello i just added a delete command field to my gridview, iam trying to get the datakey name from the row where the delete was clicked, how can i do that This is pretty simple. All you need to is the datakey name field ). protected void GridView1_RowCommand( object sender, GridViewCommandEventArgs e) { if (e.CommandName = = "Delete" ) { / / get the ID of the clicked row int ID = Convert.ToInt32(e.CommandArgument); / / Delete the record DeleteRecordByID(ID); / / Implement this on your own :) } } Catching the datakey name key in ItemStyle Width = "100px" / > < / asp:CommandField> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID = "lnkdel" runat = "server" Text = "Delete" CommandName = "Delete"> < / asp:LinkButton> < / ItemTemplate> <ItemStyle Width = "100px" / > < / asp:TemplateField> < / Columns> < / asp:GridView> In code behind protected SqlDataAdapter da = new SqlDataAdapter("", conn); da.SelectCommand = new SqlCommand("select CategoryName, CategoryID from Categories", conn); DataSet ds = new DataSet(); da.Fill(ds, "data"); gdview.DataSource = ds.Tables[0].DefaultView; gdview.DataBind
How to update, Delete and edit DataSet Is there any controls where u want to populate data using dataset or simply u have created a method which edit / update / delete.? simple way is use SqlDataAdapter and pass the commands to Update / Edit and delete. make sure that the user should have full priviliges to do this. use command builder to get the command , then call DataAdapter.Update() method using(var da = new SqlDataAdapter
I am still having getting the data-row in a Access data-base linked to my WPF project to delete. The delete button was made from following the Beth Massi video on Data input sheet and information rows are back. It is not deleteing from the Data-base .I am using a DataSet & Tableadapter Private Sub btndelete_Click( ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs view.CurrentPosition > 1 Then Dim row = CType ( Me .view.CurrentItem, System.Data.DataRowView).Row row.Delete() End If End Sub Thanks DAvid David, It is not getting deleted from the database am still at a loss of how I connect to the Access Data-base to delete a selected row using code in Xaml I have the code from Beth Massi video view.CurrentPosition > 1 Then Dim row = CType(Me.view.CurrentItem, System.Data.DataRowView).Row row.Delete() End If End Sub I copied the following from a code sample but got stuck
output parameter (derived as InputOutput) / / / where the user provided no input value. / / / < / summary> / / / <param name = "command"> The command to which the parameters will be added< / param> / / / <param name = "commandParameters"> An array of SqlParameters to be added to command< / param> private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters) { if command = = null ) throw new ArgumentNullException( "command" ); if( commandParameters ! = null ) { foreach (SqlParameter p in commandParameters) { if( p ! = null ) { / / Check for derived output p.Direction = = ParameterDirection.InputOutput | | p.Direction = = ParameterDirection.Input ) && (p.Value = = null)) { p.Value = DBNull.Value; } command.Parameters.Add(p); } } } } / / / <summary> / / / This method assigns dataRow column values to an array of SqlParameters i].Value = parameterValues[i]; } } } / / / <summary> / / / This method opens (if necessary) and assigns a connection, transaction, command type and parameters / / / to the provided command / / / < / summary> / / / <param name = "command"> The SqlCommand to be
e) { SqlConnection conn = new SqlConnection("Data Source = localhost;Initial Catalog = Customer;Integrated Security = True"); SqlCommand command = new SqlCommand("InsertDB", conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@FirstName", TextBox1.Text); command.Parameters.AddWithValue("@LastName", TextBox2.Text); command.Parameters.AddWithValue("@Code", TextBox3.Text); command.Parameters.AddWithValue("@Type", DropDownList1.SelectedValue command.Parameters.AddWithValue("@Code", TextBox4.Text); command.Parameters.AddWithValue("@Code", TextBox5.Text); command.Parameters.AddWithValue("@Code", TextBox6.Text); conn.Open(); SqlDataAdapter objadap