How to delete a row from a SQL Server CE Table with multiple JOINs?

I want to delete a record from a SQL Server CE table.
There are 3 tables scripts, options and results. I would like to remove a record from the results table. The where clause contains dynamic information which retrieved via other queries to different tables in the same database. These queries work fine and deliver
the desired data.
The Compact server is a clone of a remote table created using the sync framework. The same query to the remote table works fine.
The error I get is:
There was an error parsing the query. [ Token line number = 1,Token line offset = 10,Token in error = from ]
The code that throws the exception is as follows:
Dim connLoc As SqlCeConnection = New SqlCeConnection(My.Settings.ConnectionString)connLoc.Open()     Dim strDel As String = "Delete r from ResultsTable r inner join OptionsTable o ON o.TestName=r.TestName inner join ScriptTable c ON r.TestName=c.TestName WHERE r.TestName = '" & ds1Loc.Tables(0).Rows(0)(1) & "' AND [Index] = '" & lstIndex & "'"Dim cmdDel As SqlCeCommand = New SqlCeCommandcmdDel.CommandText = strDelcmdDel.Connection = connLoccmdDel.ExecuteNonQuery()
The values held in ds1Loc.Tables(0).Rows(0)(1) and lstIndex are
correct so should not be the problem.
I also tried using parameterised queries
Dim strDel As String = "Delete r from [ResultsTable] r inner join [OptionsTable] o ON o.TestName=r.TestName inner join [ScriptTable] c ON r.TestName=c.TestName WHERE r.TestName = @TestName AND [Index] = @lstIndex"
Dim cmdDel As SqlCeCommand = New SqlCeCommand        cmdDel.CommandText = strDel       
With cmdDel.Parameters           
.Add(New SqlCeParameter("@TestName", ds1Loc.Tables(0).Rows(0)(1)))           
.Add(New SqlCeParameter("@lstIndex", lstIndex))       
End With 
cmdDel.Connection = connLoc        cmdDel.ExecuteNonQuery()
I have tried replacing the "=" with "IN" in the the WHERE clause but this has not worked.
Is it the join that is causing the problem? I can do a select with the same search criteria and joins from the same database.
Also this query works with SQL Server. Is it perhaps that SQL CE does not support the Delete function the same as SQL Server 2008? I have been looking at this for a while now and cannot find the source of the error. Any help would be greatly appreciated.

Hello,
In SQL Server Compact, we can use join in FROM clause. The DELETE statement fail may be caused by the FOREIGN KEY constraint.
Please refer to:
DELETE (SQL Server Compact)
FROM Clause (SQL Server Compact)
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support

Similar Messages

  • How To Delete a Row From a TableView !!!!

    Hi,
    Does any know how to delete a row from a table view model.
    I have a TableViewModel being displayed, when the user select the particular row and click delete i want that particular row to be deleted.
    Any Suggestions How.
    Thanks,
    Emmanuel.

    If u want to delete single row, then set the property of TableView - selectionMode="SINGLESELECT". Select the radio button and click on delete button. In the main program, you can get the row value like...
    public void onDeleteButtonClicked(Event event) throws PageException {
    TableView table = (TableView) this.getComponentByName ("idTableView");
    DefaultTableViewModel dmodel = myBean.beanModel;
    String pid = "", row_selected;
    // Get the first visible row
    int firstVisibleRow = table.getVisibleFirstRow();
    // Get the last visible row
    int lastVisibleRow = table.getVisibleLastRow();
    for (int i = firstVisibleRow; i <= lastVisibleRow; i++) {
    if (table.isRowSelected(i)) {
      row_selected = i;
      pid = dmodel.getValueAt(i, 1).toString();
    "i" will give you the row no, pid has the value of the row at first column.
    Hope this helps.
    Thanks,
    Praveen

  • How to use open Row set in sql server 2014

    Hello All,
    How to open the row set using sql server 2014 using link server connection.

    Hi  denyy,
    Are you referring to the OPENROWSET function in SQL Server 2014?
    The OPENROWSET method is an alternative to accessing tables in a linked server and is a one-time, ad hoc method of connecting and accessing remote data by using OLE DB. The examples below demonstrate how to use the OPENROWSET function:
    A. Using OPENROWSET with SELECT and the SQL Server Native Client OLE DB Provider
    SELECT a.*
    FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',
    'SELECT GroupName, Name, DepartmentID
    FROM AdventureWorks2012.HumanResources.Department
    ORDER BY GroupName, Name') AS a;
    B. Using the Microsoft OLE DB Provider for Jet
    SELECT CustomerID, CompanyName
    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';
    'admin';'',Customers);
    GO
    C. Using OPENROWSET to bulk insert file data into a varbinary(max) column
    USE AdventureWorks2012;
    GO
    CREATE TABLE myTable(FileName nvarchar(60),
    FileType nvarchar(60), Document varbinary(max));
    GO
    INSERT INTO myTable(FileName, FileType, Document)
    SELECT 'Text1.txt' AS FileName,
    '.txt' AS FileType,
    * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document;
    GO
    D. Using the OPENROWSET BULK provider with a format file to retrieve rows from a text file
    SELECT a.* FROM OPENROWSET( BULK 'c:\test\values.txt',
    FORMATFILE = 'c:\test\values.fmt') AS a;
    Reference:
    OPENROWSET (Transact-SQL)
    Using the OPENROWSET function in SQL Server
    Thanks,
    Lydia Zhang
    If you have any feedback on our support, please click
    here.

  • How to delete number (00) in a SQL Server column ?

    how to delete number (00) in a SQL Server column ?
    example :
    column :        Births       before                     Births 
        after                          
                       199900                            
            1999
                       198200                               
         1982
                       200400                               
        2004
    help query

    You use REPLACE function to selectively replace text inside a string in SQL Server. The REPLACE function is easy to use and very handy with an UPDATE statement.
    SELECT Replace(births, '00', '')
    or
    update .....
    Also you can use STUFF()
    This function can be used for delete a certain length of the string and insert a new string in the deleted place.
    Select STUFF ('199900', 5, 2, '')
    --result 1900,1982,....
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • HOW TO DELETE THE ROW FROM DATABASE

    hI,
    Iam pasting my code below.My problem isi retrieve rows from database and display them in jsp page in rows.For each row there is delete hyperlink.Now when i click that link i should only delete the row corresponding to that delete link temporarily but it should not delete the row from database now.It should only delete the row from database when i click the save button.How can i do this can any one give some code.
    thanks
    naveen
    [email protected]
    <%@ page language="java" import="Utils.*,java.sql.*,SQLCon.ConnectionPool,java.util.Vector,java.util.StringTokenizer" %>
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Item Details</title>
    <script>
    function submitPage()
    document.details.action = "itemdetails.jsp" ;
    document.details.submit();
    </script>
    </head>
    <body>
    <form name="details" action="itemdetails.jsp" method="post">
    <%
    ConnectionPool pool;
    Connection con = null;
    Statement st;
    ResultSet rs =null;
    %>
    <table border="0" cellpadding="0" cellspacing="0" width="328">
    <tr>
    <td width="323" colspan="4"><b>Reference No :</b> <input type="text" name="txt_refno" size="14">
    <input type="submit" value="search" name="search" ></td>
    </tr>
    <tr>
    <td width="81" bgcolor="#000099"><font color="#FFFFFF"><b>Item Code</b></font></td>
    <td width="81" bgcolor="#000099"><font color="#FFFFFF"><b>Item No</b></font></td>
    <td width="81" bgcolor="#000099"><font color="#FFFFFF"><b>Amount </b></font></td>
    <td width="80" bgcolor="#000099"> </td>
    </tr>
    <%
    pool= new ConnectionPool();
    Utils utils = new Utils();
    double total =0.00;
    String search =utils.returnString(request.getParameter("search"));
    if(search.equals("search"))
    try
    String ref_no =utils.returnString(request.getParameter("txt_refno"));
    String strSQL="select * from ref_table where refno='" + ref_no + "' ";
    con = pool.getConnection();
    st=con.createStatement();
    rs = st.executeQuery(strSQL);
    while(rs.next())
    String itemcode=rs.getString(2);
    int item_no=rs.getInt(3);
    double amount= rs.getDouble(4);
    total= total + amount;
    %>
    <tr>
    <td width="81"><input type=hidden name=hitem value=<%=itemcode%>><%=itemcode%></td>
    <td width="81"><input type=hidden name=hitemno value=<%=item_no%>><%=item_no%></td>
    <td width="81"><input type=hidden name=hamount value=<%=amount%>><%=amount%></td>
    <td width="80"><a href="delete</td>
    </tr>
    <%
    }catch(Exception e){}
    finally {
    if (con != null) pool.returnConnection(con);
    %>
    <tr>
    <td width="323" colspan="4">
    <p align="right"><b>Total:</b><input type="text" name="txt_total" size="10" value="<%=total%>"></td>
    </tr>
    <tr>
    <td width="323" colspan="4">                   
    <input type="button" value="save" name="save"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    You mean when you click on the hyperlink you want that row to disappear from the page, but not delete the row from the database until a commit/submit button is pressed?
    Personally, I think I'd prefer that you have a delete checkbox next to every row and NOT remove them from the display if I was a user. You give your users a chance to change their mind about their choice, and when they're done they can see exactly which rows will be deleted before they commit.
    You know your problem, of course, so you might have a good reason for designing it this way. But I'd prefer not removing them from the display. JMO - MOD

  • HT1277 how to delete e mail from my yahoo server once i down loaded to my apple mail

    how to delete e mail from yahoo server once i down loaded to my apple mail

    Hi wh2,
    Welcome to Apple Support Communities.
    If your Yahoo account is set up as a POP account, you can set the option "Remove copy from server after retrieving a message" in the Advanced settings of Mail.
    See this article for the steps to locate this option:
    Using a POP account with multiple devices
    http://support.apple.com/kb/ht3228
    In Mail for Mac OS X 10.5 or later, choose Mail > Preferences.
    Click the Accounts tab.
    Select the account for which you wish to change the settings.
    Click the Advanced tab.
    Select the "Remove copy from server after retrieving a message" option.
    Also, this article has more information on the options found in the Advanced tab:
    Mail (Mountain Lion): Advanced accounts preferences
    http://support.apple.com/kb/PH11686
    Remove copy from server after retrieving a message
    Specify when you want to delete received messages from the mail server. You can deselect this option if you need to temporarily access messages from more than one location or computer.
    This option is available only for Post Office Protocol (POP) accounts.
    Best,
    Jeremy

  • How to delete one row from sequence

    Hi,
    i have created one table and using sequence for automatically generating id.
    i have successfully entered 5 rows....
    my problem is when i delete 3rd row, the order is changed like 1,2,4,5 but
    i want to get the data order like 1,2,3,4.
    Is it possible....plz help me...i am novice to PL/SQL

    Hi I totally agree with Satyaki_De's comment, but I still like to give the possible way....which may be trivial....
    Please follow the example.
    SQL> create table seq1(n number, a char) ;
    Table created.
    SQL> create sequence seq1seq1
    2 start with 1
    3 ;
    Sequence created.
    SQL> insert into seq1 values (seq1seq1.nextval, '&ccc');
    Enter value for ccc: a
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'a')
    1 row created.
    SQL> /
    Enter value for ccc: b
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'b')
    1 row created.
    SQL> /
    Enter value for ccc: c
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'c')
    1 row created.
    SQL> /
    Enter value for ccc: d
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'd')
    1 row created.
    SQL> /
    Enter value for ccc: e
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'e')
    1 row created.
    SQL> /
    Enter value for ccc: f
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'f')
    1 row created.
    SQL> commit ;
    Commit complete.
    SQL> select * from seq1 ;
    N A
    1 a
    2 b
    3 c
    4 d
    5 e
    6 f
    6 rows selected.
    SQL> delete from seq1 where n = 3 ;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> select * from seq1;
    N A
    1 a
    2 b
    4 d
    5 e
    6 f
    SQL> update seq1 set n = n -1 where n > 2 ;
    3 rows updated.
    SQL> select * from seq1 ;
    N A
    1 a
    2 b
    3 d
    4 e
    5 f
    SQL> drop sequence seq1seq1 ;
    Sequence dropped.
    SQL> create sequence seq1seq1 start with 6 ;
    Sequence created.
    SQL> insert into seq1 values (seq1seq1.nextval, '&ccc')
    2 ;
    Enter value for ccc: g
    old 1: insert into seq1 values (seq1seq1.nextval, '&ccc')
    new 1: insert into seq1 values (seq1seq1.nextval, 'g')
    1 row created.
    SQL> select * from seq1 ;
    N A
    1 a
    2 b
    3 d
    4 e
    5 f
    6 g
    6 rows selected.
    regards
    JC

  • How to delete single row from multiple

    Hi:l
    This is my query which provides duplicate rows in my table:
    select count(*),CUSTMAST_REQUEST_SRNO,ACTIVITYMAST_SRNO,STATUSMAST_SRNO from REQUEST_TRANS having count(*)>1 group by CUSTMAST_REQUEST_SRNO,ACTIVITYMAST_SRNO,STATUSMAST_SRNO;
    O/p:
    2 |M984 | 74 |M6
    2 |M985 | 74 |M6
    2 |M987 | 74 |M6
    2 |M992 | 74 |M6
    2 |M995 | 74 |M6
    2 |M998 | 74 |M6
    Here output shows that CUSTMAST_REQUEST_SRNO M984 having two same rows. And now i want
    to delete any one of row from that. So, how can i apply it for multiple rows ?
    Can any body help-out me in that?
    Thank You,
    Anup Desai
    Edited by: user11688398 on Feb 13, 2013 10:39 PM

    If you want to delete all Duplicates and retain Only One row then Below:
    delete from REQUEST_TRANS a
    where rowid < ( select max(rowid) from REQUEST_TRANS b where a.CUSTMAST_REQUEST_SRNO = b.CUSTMAST_REQUEST_SRNO and a.ACTIVITYMAST_SRNO = b.ACTIVITYMAST_SRNO ... )

  • How to delete zero rows from a matrix?

    Hi,
    I have a 2D datamatrix and there are some zero rows. My original program should recognize all zero rows and delete them. How to do that?
    I have tried with the Delete From Array function but no success. I also tried with the OpenG array functions but...no.
    I attached a vi which simulates my problem. There is one zero row and I want to delete it and have a matrix without zero rows.
    Kudos for any good help!
    Solved!
    Go to Solution.
    Attachments:
    DeleteZeroRows.vi ‏19 KB

    Christian_M wrote:
    The idea was to give a hint that people try using their brain....
    Stilll, I think your code is fundamentally flawed and will thus lead the student into a deep swamp.
    Have you actually tried it with multiple rows of zeroes?
    Since "delete from array" rearranges the array indices with each deletion, the code will break if there is more than one row to be deleted. For example if a row is already deleted and it needs to also delete the last row, it would try to delete a row that no longer exists. If a later row still exists, it will delete the wrong row.
    Also, since NaN gets coerced to a valid index (2147483647), it's probably not such a good idea. "-1" would be a better choice. (Well, it's an unlikely implossible possibility in LabVIEW 32 bit, but still....)
    I also don't understand your logic with "search array". You need to test all elements for zero.
    LabVIEW Champion . Do more with less code and in less time .

  • How to delete the row from the ADF table using popup box

    Hi,
    I have one requirement like need to delete a record from the table, but that time need to show one popup window for confirmation of the deletion. I am using Delete buttom from the vo operations. I am able to delete the row with out popup but when i used the popup that time deletion is not happening.
    Can any one help me in this.
    Regards,

    Issue was resolved.

  • How To Delete a row from view object

    Hi
    I have a table whose data is populated based on the view object... and for each row i have a delete icon...
    when i press on this delete icon i want to delete that particular row from the view object only..but not from the data
    base..please help me in this issue
    Thanks

    Hi,
    as per krishna priya says u can delete .
    -----1st one thing let me know vo is eo based .???.
    If not here is the sample code to delete a row not from the data base.:
    public void Deleterow(OAPageContext pageContext, OAWebBean webBean,String prjid)
    int idtodelete;
    int fetchedrowcount;
    Number prjojectid;
    RowSetIterator deleteIter;
    prjidtodelete=Integer.parseInt(prjid);
    OADBTransaction tr = getOADBTransaction();
    ProjectsVORowImpl row=null;
    ProjectsVOImpl vo= getProjectsVO1();
    fetchedrowcount=vo.getRowCount();
    deleteIter = vo.createRowSetIterator("deleteIter");
    deleteIter.setRangeStart(0);
    deleteIter.setRangeSize(fetchedrowcount);
    for(int i=0;i<fetchedrowcount;i++)
    row= (ProjectsVORowImpl)deleteIter.getRowAtRangeIndex(i);
    prjojectid=(Number)row.getAttribute("ProjectId");
    if (prjojectid.compareTo(prjidtodelete)==0)
    row.remove();
    break;
    deleteIter.closeRowSetIterator();
    Regards
    Meher Irk
    Edited by: Meher Irk on Nov 2, 2010 12:42 AM

  • How to delete a row from AbstractTableModel

    my table is using an object to populate the data.
    static Object[][] data = new Object[LineCount()][5];
    So when I delete a row, I should delete from the model or the object?
    Rgds

    When you populate your table with a two dimensional array, the table actually creates a DefaultTableModel (which extends AbstractTableModel). The DefaultTableModel has methods which allow you to add/remove row from the data model. Read the DefaultTableModel API for more information.

  • How To Delete a Row From a DataGrid

    Hai
         I have attached a mxml in a txt format. because i am unable to attach the mxml, pl copy this txt file into flex and run the application.
      1. Run the application.
      2. Enter values in the textbox and click add, values will be added to the datagrid.
      3. now click AND or OR and then change the values in the second and thrid combobox and again click add.
      4.Like wise change the combobox values and add five rows to the datagrid.
    5.now if u delete the last row u can see the curent last row in the combobox, so that the AND or Or can be added to it
    6. now if u delete a row in between, the deleted row's value oly maintains in the combobox,so i am unable to add AND or Or to the grid
      7.I need the last row data in the datagrid to be in the second and third combobox, which ever row is deleted.
    Can anyone help me....
    Thanks in advance.

    Except refresh() will not help, it only causes any sort or filter to be re-applied.  Use the collection API(removeItemAt()) to delete the item and the UI will update correctly.
    Tracy Spratt

  • How to get selected row from a non-bind ADF table

    Hi,
    I have an ADF table that is based on a collectionModel built programmatically. The collectionModel is this:
    model = new SortableModel(new ArrayList<ArrayList>());
    Hence, it is not a binding table. My question is how to get the selectedRows from a non-bind table.
    I am used to building binding ADF table and I know we can get it from voiterator.getCurrentRow, since the selectionListener is set to the binding....collectionModel.makeCurrent
    <af:table value="#{bindings.ItasLookupTypesVO1.collectionModel}"
    selectedRowKeys="#{bindings.ItasLookupTypesVO1.collectionModel.selectedRow}"
    selectionListener="#{bindings.ItasLookupTypesVO1.collectionModel.makeCurrent}"
    </af:table>
    I am thinking maybe I need to write my own selectionListener, but need more advice/ideas of what's the codes in the customer selection Listener to get it from my SortableModel.
    Please help.
    Thanks
    -Mina

    I'm not sure if this works in your case, but check out the selection listener I write in this blog http://wp.me/pcBZk-eu
    You should use the selection event and check the added set. This should give you access to the selected row.
    Timo

  • How to delete empty row without validation error in ADF Table(EMP)

    Hi Everyone,
    I am using EMP Table in ADF jspx page to insert the data into database.when i insert a row into table by createInsert operation,it inserting the row.But I need to delete that row immediately with out entering any value.
    But it showing some validation error at empno.Is there any ways to delete the empty row?if not,what are the reasons that we can't delete the row.
    could any one tell me the reasons!!
    Thanks in advance!!
    With Best Regards,
    Amar
    Edited by: 973755 on Dec 11, 2012 6:42 AM

    Amar,
    I am little confused with your logic here.....
    but if you are trying to remove the row by clicking Remove button, you can set the immediate property to true and that remove function will run without executing any entity validation.......
    -R

Maybe you are looking for