468,134 Members | 1,188 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

delete statement

20
hi,
i'm working in asp.net using visual studio 2005 with vb language,
my tables is access database, will i'm trying to write the delete statement to delete some fields in my tables i wrote this statement and have no errors but the row didn't deleted. here is my code:

Expand|Select|Wrap|Line Numbers
  1. Public Function DeleteQuestion(ByVal Question_ID As Integer)
  2.         Dim cmd As New OleDbCommand("Delete from Questions where Question_id= @Question_id)", conn)
  3.         Try
  4.             conn.Open()
  5.             cmd.ExecuteNonQuery()
  6.         Catch ex As Exception
  7.             ex.Message.ToString()
  8.         End Try
  9.         conn.Close()
  10.         If er = "" Then
  11.  
  12.             Return "the Question has been Deleted succefully!!!!"
  13.  
  14.         Else
  15.  
  16.             Return er
  17.         End If
  18.     End Function
  19. End Class
so any one can help or tell me where the problem is or if i miss something here????
Jan 6 '08 #1
3 996
Shashi Sadasivan
1,435 Expert 1GB
How did you check that no exceptions were thrown?

From your code, if the exception occours, you are creating a reference of the message exception string but nothing happens with that reference.

it would be better if you put it in a messagebox so some output window.

Since your database is Access you should use brackets around field names

Expand|Select|Wrap|Line Numbers
  1. Delete from [Questions] where [Question_id]= @Question_id
The other thing about the command you wrote is, what is @Question_id ?
when and wher are u assigning it?


Your query should look more likee
Expand|Select|Wrap|Line Numbers
  1. Delete from [Questions] where [Question_id]= ?
and use the AddParameter method for the sql command
Jan 6 '08 #2
kunal pawar
297 100+
try this code

Expand|Select|Wrap|Line Numbers
  1. Dim cmd As New OleDbCommand("Delete from Questions where Question_id=" & Question_ID , conn)
  2.  
  3. And update ur function 
  4. Public Function DeleteQuestion(ByVal Question_ID As Integer)
  5.         Dim cmd As New OleDbCommand("Delete from Questions where Question_id=" & Question_ID , conn)
  6.         Try
  7.             conn.Open()
  8.             cmd.ExecuteNonQuery()
  9.         Catch ex As Exception
  10.             ex.Message.ToString()
  11.         End Try
  12.         conn.Close()
  13.         If er = "" Then
  14.  
  15.             Return "the Question has been Deleted succefully!!!!"
  16.  
  17.         Else
  18.  
  19.             Return er
  20.         End If
  21.     End Function
  22. End Class
Jan 7 '08 #3
zaiena
20
try this code

Expand|Select|Wrap|Line Numbers
  1. Dim cmd As New OleDbCommand("Delete from Questions where Question_id=" & Question_ID , conn)
  2.  
  3. And update ur function 
  4. Public Function DeleteQuestion(ByVal Question_ID As Integer)
  5.         Dim cmd As New OleDbCommand("Delete from Questions where Question_id=" & Question_ID , conn)
  6.         Try
  7.             conn.Open()
  8.             cmd.ExecuteNonQuery()
  9.         Catch ex As Exception
  10.             ex.Message.ToString()
  11.         End Try
  12.         conn.Close()
  13.         If er = "" Then
  14.  
  15.             Return "the Question has been Deleted succefully!!!!"
  16.  
  17.         Else
  18.  
  19.             Return er
  20.         End If
  21.     End Function
  22. End Class

hello,
i'm trying your statement and i'ts totaly work thank you very much.
Jan 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by php newbie | last post: by
4 posts views Thread by Stefan Strasser | last post: by
16 posts views Thread by robert | last post: by
4 posts views Thread by AlanAylett | last post: by
1 post views Thread by Matt | last post: by
12 posts views Thread by yufufi | last post: by
8 posts views Thread by Michel Esber | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.