Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2006, 04:05 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with delete statement

here is the code for del.aspx

<form name="form1" method="post" action="table1.aspx">
        <%
        dim cv as string
    dim str as string
    Dim strConnection As String = "user id=sa;password=;server=.;initial catalog=students"
    Dim cn As SqlConnection = New SqlConnection(strConnection)
     cn.Open()
     str=(Request.QueryString("cv"))
         Dim strSelect As String = "DELETE teachers where TID ='"& str &"' "
     response.write(strSelect)
    ' response.End()
     Dim sqlComm As new SqlCommand(strSelect,cn)
     try
     sqlComm.ExecuteNonQuery()
     catch ex as exception
     response.Write(ex.ToString())
     finally
     cn.close()
     end try
'response.redirect("Teachview.aspx")

        %>
        </form>
my sql statement passing value is correct,

DELETE teachers where TID ='1' System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ' '. at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at ASP.del_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer) in http://localhost/add/del.aspx:line 32


Line 32 is the sqlcomm.executenonquery() method.its in this statement error is there.i duno wats wrong.if anybody knows pls tel me.

Reply With Quote
  #2 (permalink)  
Old February 22nd, 2006, 11:00 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Is TID a string data type of numerical (int, for example)? Your DELETE statment is using TID as a string.

Reply With Quote
  #3 (permalink)  
Old February 23rd, 2006, 04:35 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

TID is a nvarchar.

Reply With Quote
  #4 (permalink)  
Old February 23rd, 2006, 05:07 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure what SQL variation your are using, but it looks like you are missing the FROM statement in your SQL statement.

Try "DELETE FROM teachers WHERE TID ='"& str &"';"

- A.Kahtava
Reply With Quote
  #5 (permalink)  
Old February 23rd, 2006, 08:08 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i did use from statement b4.then a memeber in wrox told me to remove it.and it was working perfectly fine with with my above sql statement.but after few days i rerun it,its not working.

Reply With Quote
  #6 (permalink)  
Old March 23rd, 2006, 01:01 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to demiwolf
Default

When deleting items, you usually need to declare what table you are deleting from. Be careful, because a wayward delete statement can toss ALL of the data in your table/database.

Reply With Quote
  #7 (permalink)  
Old March 23rd, 2006, 01:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

This statement:

    Dim strSelect As String = "DELETE teachers where TID ='"& str &"' "

seems a bit suspicious. There looks like there is a trailing space (which shouldn't hurt) or worse, some nonprintable character.

How about:

    Dim strSelect As String = "DELETE teachers where TID ='" & str & "'"

The resultant

    DELETE teachers where TID = '1'

is correct syntax, so if this fails something else is going on.

As an aside, the FROM keyword in a DELETE statement is optional.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Statement Error Jane SQL Language 1 October 21st, 2005 01:45 PM
T-SQL Delete statement Alcapone C# 3 November 3rd, 2004 01:08 PM
sql delete statement sand133 VB Databases Basics 2 July 7th, 2004 10:56 PM
delete problem hosefo81 PHP Databases 1 March 7th, 2004 07:40 AM
DELETE statement with ASP.NET kaz VS.NET 2002/2003 1 December 9th, 2003 09:35 PM



All times are GMT -4. The time now is 04:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.