使用组合框搜索并在文本框中过滤结果

时间:2017-08-13 16:01:30

标签: vb6

我正在尝试在VB 6.0上做一个小程序来查找数据库中的记录并根据组合框选择在文本框中打印但是我找不到允许我这样做的代码。

请帮助。

Dim adoCon
Dim adoRs
Dim strSQL As String


Dim strDB As String

'Change YourDatabaseName to actual database you have
strDB = "c:\path\YourDatabaseName.accdb"



Set adoCon = CreateObject("ADODB.Connection")
adoCon.Open "Provider = Microsoft.ACE.OLEDB.12.0; " & _
"Data Source = " & strDB & ";" & _
"Persist Security Info = False;"

'Change Table1 to your table name in MS Access
'change the name of combobox and the fieldname in MS Access table
'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''
' if combo is numeric 
strSQL = "SELECT [fieldNameToReturn] FROM Table1 Where [fieldName] = " + [combo].Value + ";"

' if combo is text
'strSQL = "SELECT [fieldNameToReturn] FROM Table1 Where [fieldName] = '" + [combo].Value + "';"
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''

Set adoRs = CreateObject("ADODB.Recordset")

'Set the cursor type we are using so we can navigate through the recordset
adoRs.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
adoRs.LockType = 3

'Open the tblComments table using the SQL query held in the strSQL varaiable
'adoRs.Open strSQL, adoCon

If Not adoRS.Eof() Then
[yourTextBox] = adoRs(0)
End If 
adoRs.Close
adoCon.Close
Set adoRs = Nothing
Set adoCon = Nothing

1 个答案:

答案 0 :(得分:0)

" BOF"下面不是拼写错误。如果记录集为空(查询没有返回记录),BOF将为真。

    BeaconManager beaconManager;
Button button;

@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_mainr);

    beaconManager = BeaconManager.getInstanceForApplication(this);
    button.setOnClickLister(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                        moveList();
                    }
         });

            startBeacon();
           }


    @Override
     public void onBeaconServiceConnect() {

            beaconManager.setRangeNotifier(new RangeNotifier() {
                @Override
                public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {

                Log.d("BeaconInfo","" + collection.size());

             }
         });

            try {
                    beaconManager.startRangingBeaconsInRegion(defaultRegion);
             } catch (RemoteException e) {
                 e.printStackTrace();
                }

      }


    private void startBeacon(){
                beaconManager.bind(this);
            }

    private void stopBeacon(){  
                beaconManager.unbind(this);
            }

public void moveList(){

        stopBeacon();

        Intent intent = new Intent(this,ListActivity.class);

        startActivity(intent);

        finish();

    }

如果您正在处理多个记录,您仍然会执行MoveFirst,然后循环直到EOF为真,处理每条记录。当没有更多记录要处理时,MoveNext将设置EOF = True。

adoRs.Open strSQL, adoCon
If Not adoRS.BOF Then
    'If not _BOF_ we have records so load the first record
    adoRs.MoveFirst

    'If first field is a string then use this
    [yourTextBox] = adoRs.Fields(0).Value

    'If first field is numeric then use this
    [yourTextBox] = CStr(adoRs.Fields(0).Value)
Else
    Msgbox "No records returned."
End If