Results 1 to 2 of 2

Thread: help deleting row

  1. #1

    Thread Starter
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 2010
    Location
    MSDN Library
    Posts
    259

    Resolved help deleting row

    guys help me with this

    i put the code into button
    Code:
     Dim connect As New OleDbConnection(conString)
                connect.Open()
    
                Dim dsql As String
               
    
                dsql = "DELETE FROM InventoryItem"
                dsql = dsql & "WHERE TransactionDate = '" & TransactionDateText.Text & "'AND "
                dsql = dsql & " ItemName = '" & ItemNameText.Text & "' AND Quantity = '" & QuantityText.Text & "' AND"
                dsql = dsql & " Price = '" & PriceText.Text & "' AND Cost = '" & CostText.Text & "' AND"
                dsql = dsql & " Type = '" & InTextbox.Text & "'"
    but when i click the button it gives me an error

    the error is "Syntax Error in FROM clause"

    help me guys sorry new in vs 2008
    Last edited by marniel647; Apr 8th, 2011 at 09:20 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help deleting row

    This is a classic example of not looking at the data you're actually using. Don't just look at the code. Look at the data. Put this line after that code:
    Code:
    MessageBox.Show(dsql)
    and the mistake should be obvious.

    Also, why do this:
    Code:
                dsql = "DELETE FROM InventoryItem"
                dsql = dsql & "WHERE TransactionDate = '" & TransactionDateText.Text & "'AND "
                dsql = dsql & " ItemName = '" & ItemNameText.Text & "' AND Quantity = '" & QuantityText.Text & "' AND"
                dsql = dsql & " Price = '" & PriceText.Text & "' AND Cost = '" & CostText.Text & "' AND"
                dsql = dsql & " Type = '" & InTextbox.Text & "'"
    when you can just do this:
    Code:
                dsql = "DELETE FROM InventoryItem" _
                & "WHERE TransactionDate = '" & TransactionDateText.Text & "'AND " _
                & " ItemName = '" & ItemNameText.Text & "' AND Quantity = '" & QuantityText.Text & "' AND" _
                & " Price = '" & PriceText.Text & "' AND Cost = '" & CostText.Text & "' AND" _
                & " Type = '" & InTextbox.Text & "'"
    Further to that, don't use string concatenation to insert variables into SQL code at all. Follow the Blog link in my signature and check out my post on ADO.NET parameters.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width