Home > Software engineering >  ListView how to delete a row data in the database specified?
ListView how to delete a row data in the database specified?

Time:09-19


ListView how to delete a row data in the database specified?
The original poster using VB to write a ListView, wanted to Access database operation
Such as choosing ListView the third row, click "delete", just delete Access the third row,
For a long time, but finds no found this command,
Online is delete from the database name where name=hey,
Not for me,

The following code?
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Dim a
A=ListView1. SelectedItem. Index "this article is the mouse's ListView the number of rows
The first line a
delete the database name-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Novice, please advice,

CodePudding user response:

Fyi:
 
ListView introduction: complete code


In a ListView in claim 1 to 4 to discuss the code, in addition to the process of filling the TreeView control, are given below, for filling the TreeView control code, please refer to the "TreeView control: to bind the TreeView to Biblio. MDB database", to get a working example of this code, please refer to the columns in the example application Samples catalogue DataTree. VBP,

'general statement
Private mDbBiblio As Database 'Database variables,

Private Sub Form_Load ()
'open the Biblio. MDB and the object variable
'set to the database,
The Set mDbBiblio=DBEngine. Workspaces (0). _
OpenDatabase (" Biblio. MDB)

'filling TreeView control code
'didn't give here,
End Sub

Private Sub tvwDB_NodeClick (ByVal Node As the Node)
'to check if the Tag is "Publisher", if it is, is
'call MakeColumns process, and then call
'GetTitles function,
If the Node. The Tag="Publisher" Then
MakeColumns
GetTitles Val (Node. Key)
End the If
End Sub

Private Sub MakeColumns ()
'set to empty ColumnHeaders,
LvwDB. ColumnHeaders. Clear
'add four ColumnHeader,
LvwDB. ColumnHeaders. Add, "Title", 2000
LvwDB. ColumnHeaders. Add,, "the Author"
LvwDB. ColumnHeaders. Add, "Year", 350
LvwDB. ColumnHeaders. Add,, "ISBN"
End Sub

Private Sub GetTitles (PubID)
'delete the old books,
LvwDB. ListItems. Clear
'statement you an object of type variables,
Dim rsTitles As you
'for the record, only to find the same PubID bibliographic query
'create a recordset,
'each record of the recordset,
'add ListItem ListView control object,
'and record the Title, ISBN and Author field
'set up the new attributes of the object,
The Set rsTitles=mDbBiblio. OpenRecordset _
(" select * from Titles where PubID="& amp; PubID)

Do Until rsTitles. EOF
'add a ListItem,
Set mItem=lvwDB. ListItems. The Add ()
MItem Text=rsTitles! The TITLE
MItem. SmallIcon="smlBook"
MItem. Icon="book"
MItem Key=rsTitles! ISBN
'with the function and set the author
'SubItems (1) properties,
MItem. SubItems (1)=GetAuthor (rsTitles! ISBN)
If Not IsNull (rsTitles! Then [Year Published])
MItem. SubItems (2)=_
RsTitles! [Year Published]
End the If
MItem. SubItems (3)=rsTitles! ISBN
RsTitles. MoveNext
Loop
End Sub

Private Function GetAuthor (ISBN)
'statement DAO object variables,
Dim rsTitleAuthor As you
Dim rsAuthors As you
'the object variable is set to record sets,
The Set rsTitleAuthor=mDbBiblio. _
OpenRecordset (the Title "Author", dbOpenDynaset)
The Set rsAuthors=mDbBiblio. _
OpenRecordset (" the Authors ", dbOpenDynaset)
'create a query string,
Dim strQuery As String
StrQuery="ISBN=" & amp; "'" & amp; ISBN & amp; "'
"RsTitleAuthor. FindFirst strQuery
'if there is no author, return "n/a",
'otherwise, return the names of the authors,

If rsTitleAuthor. NoMatch Then
GetAuthor="n/a"
The Exit Function
The Else
'assumption that found the correct record sets,
'and then use Au_ID field values to set the query string,
'and search for "author" table,
StrQuery="Au_ID=" & amp; RsTitleAuthor! AU_ID
RsAuthors. FindFirst strQuery
'return to the Author field of the Author's last name,
GetAuthor=rsAuthors! The Author
End the If
End the Function

CodePudding user response:

1, citing ado controls
2, connect to the database
3, access to the selected lines to delete command

This is the best way to the serial number to delete, you get the method of field

Listview1. ListItems. Item (1). SubItems (1)

This means, the value of line 1 column 1
  • Related