Home > Software engineering >  VB how to use the SQL query shows the result?
VB how to use the SQL query shows the result?

Time:10-03



Has a table books, requirements when I was in me. The textbox1. Enter the ISBN number, text me. Textbox2. The text displayed in the database corresponding to the title, I think I know want to use the select title from books where ISBN='" & amp; Me. Textbox1. Text & amp; "'" but don't know how to show the input results.
Could you tell me how to play the code? I am a novice, you can tell the complete code, thank you

CodePudding user response:

For a simple example:
 Option Explicit 
Private MyConn As ADODB. Connection
Private Sub Form_Load ()
"Open the database
On Error GoTo 100
Dim ConnStr As String
"Open the database
ConnStr="provider=Microsoft. Jet. The oledb. 4.0. The data source=d: \ db1 MDB
""' if there is a password database, add the following
"' ConnStr=ConnStr & amp; "; The jet oledb: database password=123456
"The Set MyConn=New ADODB. Connection
MyConn. The ConnectionString=ConnStr
MyConn. Open
The Exit Sub
100:
MsgBox Err. The Description
End Sub
Private Sub Form_Unload (Cancel As Integer)
'close the database
MyConn. Close
The Set MyConn=Nothing
End Sub
Private Sub Text1_Change ()
Text2. Text=GetBookName (Text1. Text)
End Sub
The Function GetBookName (ByVal bIsbn As String) As String
On Error GoTo incremented
"' read data
Dim the Rs As New ADODB library. You, mySQL As String
MySQL="select * from books where isbn='" & amp; Trim (bIsbn) & amp; "'" '
Rs. The Open mySQL, MyConn, adOpenKeyset, adLockOptimistic
With the Rs
If the RecordCount & gt; 0 Then
GetBookName=. Fields (" title "). The Value
End the If
End With
Rs. Close
Set the Rs=Nothing
The Exit Function
Is incremented:
GetBookName=Err. The Description
End the Function

CodePudding user response:

In principle is upstairs in the general, but the original poster you this is VB.NET, ADO.NET is commonly used in way, in fact you find about VB.NET database programming introductory article take a closer look at as well:)
Such as the corresponding blog.csdn.net
  • Related