| |

VerySource

 Forgot password?
 Register
Search
View: 667|Reply: 2

VB6 database query problem data type mismatch in standard expressions

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-17 23:40:01
| Show all posts |Read mode
VB6 database query problems:
The code looks like this:
Where cbSearch is a drop-down list box, the connected database is the access2000 database
If txtSearch.Text = "" Then
        MsgBox "Query criteria cannot be empty!", VbOKOnly + vbInformation, "Query"
    Else
        Adodc1.RecordSource = "select * from sales information table where"&Trim (cbSearch.Text)&"= '"&Trim (txtSearch.Text)&"'"
        Adodc1.Refresh
        If Adodc1.Recordset.EOF Then
            MsgBox "No records found for this condition!", VbOKOnly + vbInformation, "Query"
        End If
    End If
The problem is, for example, when entering a condition in txtSearch, when the entered condition is different from the type in the database, vb pops up an error window: the data type in the standard expression does not match
For example Adodc1.RecordSource = "select * from sales information table where serial number = '"&Trim (txtSearch.Text)&"'"
This sequence number field is numeric in access, and a data type mismatch error in the standard expression will pop up

Because the&connector is used to connect the operands of two disks, whether it is a character or a numeric type, before the connection operation is performed.
'It is caused by the system first converting the operator number to a character type and then connecting. I do not want to change the database.
Seeking a solution.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-18 18:30:02
| Show all posts
Adodc1.RecordSource = "select * from sales information table where serial number ="&Trim (txtSearch.Text)
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-20 10:15:01
| Show all posts
"select * from sales information table where serial number ="&Trim (txtSearch.Text)&""
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list