473,378 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1230
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

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

Similar topics

14
by: php newbie | last post by:
I am getting error messages when I try to delete from a table using the values in the table itself. The intent is to delete all rows from TableA where col_2 matches any of the col_1 values. ...
4
by: Stefan Strasser | last post by:
why is delete an expression and not a statement? (in my draft copy of the standard). I was about to ask the same question about "throw" but found an expression case of throw("return boolvalue ? 5...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
4
by: AlanAylett | last post by:
Hi all wondering if anybody could spot anything wrong with this SQL DELETE statement, both my Access and SQL skills are not what they used to be so i reckon its something simple, any suggestions...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
1
by: Matt | last post by:
I am writing a DELETE statement and I want to filter the records using another SELECT statement. My SELECT statement is a GROUP BY query that grabs all social security numbers from the "Data...
12
by: yufufi | last post by:
Hello, How does delete know how much memory to deallocate from the given pointer? AFAIK this informations is put there by new. new puts the size of the allocated memory before the just before...
3
by: atrottier | last post by:
I'am new here so I'd like to say hello and this seems to be a great site it has already helped me a few times. I just got an assignment to correct and modify a simple access application. First some...
1
by: codedhacker | last post by:
I have a piece of code that uses the db-library with sql server 2000/2005 and runs the following delete statement: DELETE FROM TABLE1 WHERE COL1 IN( 'Some Val1' ) AND COL2 IN( 'Some Val2' )...
8
by: Michel Esber | last post by:
Hello, Env: DB2 V8 LUW FP16 running Linux create Table X (machine_id varchar(24) not null, ctime timestamp not null); create index iFoo on X (MACHINE_ID, CTIME) allow reverse scans; alter...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.