i got a button called delete and when i enter in a order id (shown in the pic) and click on delete it goes into the database find the id and the row of informationand deletes it, i want some information on how i can this can be done?? idea anyone please

|
| Neetan Thursday, March 02, 2006 5:31 PM |
db1.connection should be an actual connection string.
refer to http://www.connectionstrings.com for future use
For MSAccess, it is:
so the code would look like
Private Sub cmdDelete_Click() Dim db1 As ADODB.Command db1 = New ADODB.Command db1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=a:\db1.mdb;User Id=admin;Password=;" db1.CommandType = adCmdText db1.CommandText = "delete * from order where orderid=" & txtOrder.Text db1.Execute End With End Sub |
| Jazz4sale Thursday, March 02, 2006 8:02 PM |
ok did that and this is code that i put in,
DELETE * FROM Orders WHERE ID=1;
and is deleted record number 1 :-S |
| Neetan Thursday, March 02, 2006 8:43 PM |
Step through the code and make sure the textbox is actually containing the id that you want to search by. Since you are building your where clause with that piece of information then my guess it's not containing anything and when the statement is executed it's not finding any records that meet the criteria. In other words, when you execute the statement and the textbox is not containing the id, the statement that is passed looks like this:
delete * from order where orderid=
one thing you could do is check the statement by adding this code
msgbox db1.commandtext
before the execute command.
This will show you what statement is actually being executed. |
| Jazz4sale Friday, March 03, 2006 2:21 PM |
You would have to use a Command object like OLEDBCommand or SQLClientCommand
google deleting records ado.net vb.net
I always start there because I end up finding different ways of doing the same thing and also learn other things I didn't know how to do. |
| Jazz4sale Thursday, March 02, 2006 6:10 PM |
i tryed this but it totally wrong :-(
Private Sub cmdDelete_Click() Dim db1 As ADODB.Recordset Set db1 = New ADODB.Recordset db1.Open "SELECT * FROM Order Where OrderID=txtOrder" If Not ar.EOF Then db1.Delete db1.Update End If End Sub |
| Neetan Thursday, March 02, 2006 6:18 PM |
Are you using vb6?
Just to make sure you know, this is a VB.NET forum.
But regardless, what I said still applies to you.
Dim db1 As ADODB.Command db1 = New ADODB.Command
With db1 .ActiveConnection = "CONNECTIONSTRING" .CommandType = adCmdText .CommandText = "delete * from order where orderid=" & txtOrder.Text .Execute End With
|
| Jazz4sale Thursday, March 02, 2006 6:29 PM |
yeh i am using vb6, ohhh sorry i guesss i don't knowanywhere else togo for help <goes all shy>, and i'm getting getting an error
invaild use of property
the code looks like
Private Sub cmdDelete_Click() Dim db1 As ADODB.Command db1 = New ADODB.Command db1.ActiveConnection = "A:\db1.mdb" db1.CommandType = adCmdText db1.CommandText = "delete * from order where orderid=" & txtOrder.Text db1.Execute End With End Sub
|
| Neetan Thursday, March 02, 2006 7:40 PM |
db1.connection should be an actual connection string.
refer to http://www.connectionstrings.com for future use
For MSAccess, it is:
so the code would look like
Private Sub cmdDelete_Click() Dim db1 As ADODB.Command db1 = New ADODB.Command db1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=a:\db1.mdb;User Id=admin;Password=;" db1.CommandType = adCmdText db1.CommandText = "delete * from order where orderid=" & txtOrder.Text db1.Execute End With End Sub |
| Jazz4sale Thursday, March 02, 2006 8:02 PM |
its not deleting the row :-S and the table names are right :-S |
| Neetan Thursday, March 02, 2006 8:18 PM |
Make sure you are hitting the right database (I wouls suggest moving it from the A drive to your C drive, remember you have to change the path in the connection string). Also, run the script in access as a query and see if it deletes it. This way you'll see if it's something with the statement. If it does then step through the code and see that the text box is actually being concatenated to the statement.
|
| Jazz4sale Thursday, March 02, 2006 8:22 PM |
okay i've moved it to my c: drive and changed the source, what do you mean by "run the script "? |
| Neetan Thursday, March 02, 2006 8:31 PM |
copy the statement "delete * from..." into a new MSAccess query and see that it's property formated. This will ensure that it's nothing to do with the statement. |
| Jazz4sale Thursday, March 02, 2006 8:32 PM |
ok did that and this is code that i put in,
DELETE * FROM Orders WHERE ID=1;
and is deleted record number 1 :-S |
| Neetan Thursday, March 02, 2006 8:43 PM |
Step through the code and make sure the textbox is actually containing the id that you want to search by. Since you are building your where clause with that piece of information then my guess it's not containing anything and when the statement is executed it's not finding any records that meet the criteria. In other words, when you execute the statement and the textbox is not containing the id, the statement that is passed looks like this:
delete * from order where orderid=
one thing you could do is check the statement by adding this code
msgbox db1.commandtext
before the execute command.
This will show you what statement is actually being executed. |
| Jazz4sale Friday, March 03, 2006 2:21 PM |
consider this fixed :-D |
| Neetan Friday, March 03, 2006 2:23 PM |
Click on Mark as Answer next to the post that fixed the issue so that the newsgroup builds a good KB. Your question and its answer could help someone in the future. |
| Jazz4sale Friday, March 03, 2006 2:27 PM |