p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2000 (http://p2p.wrox.com/forumdisplay.php?f=20)
-   -   problem with delete statement (http://p2p.wrox.com/showthread.php?t=38881)

thas123 February 22nd, 2006 04:05 PM

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.


SQLScott February 22nd, 2006 11:00 PM

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


thas123 February 23rd, 2006 04:35 AM

Hi,

TID is a nvarchar.


adam_kahtava February 23rd, 2006 05:07 AM

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

thas123 February 23rd, 2006 08:08 AM

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.


demiwolf March 23rd, 2006 01:01 PM

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.


Jeff Mason March 23rd, 2006 01:13 PM

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


All times are GMT -4. The time now is 07:01 PM.

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