Home > Back-end >  Wait for a great god (based on c builder6.0 design a query function, access database) compiled no er
Wait for a great god (based on c builder6.0 design a query function, access database) compiled no er

Time:10-11

AnsiString an1=" select * from worker where ";
If (Edit1 - & gt; The Text!="")
An1 +="num='" + Form5 - & gt; Edit1 - & gt; The Text + "' and";
If (Edit2 - & gt; The Text!="")
An1 +="wname='" + Form5 - & gt; Edit2 - & gt; The Text + "' and";
AnsiString xb="";
If (Form5 - & gt; RadioButton1 - & gt; Checked==1)
Xb="male";
If (Form5 - & gt; RadioButton2 - & gt; Checked==1)
Xb="female";
If (xb!="")
An1 +="sex='" + xb +"' and ";
If (Edit3 - & gt; The Text!="")
An1 +="id='" + Edit3 - & gt; The Text + "' and";
If (ComboBox1 - & gt; The Text! Please select the "=")
An1 +="department='" + ComboBox1 - & gt; The Text + "'";
An1 +="' department!="" '";

CodePudding user response:

ADOQuery1 - & gt; SQL - & gt; The Clear ();
ADOQuery1 - & gt; SQL - & gt; Add (an1);
ADOQuery1 - & gt; The Open ();
If (ADOQuery1 - & gt; RecordCount==0)
{ShowMessage (" I'm sorry, didn't you want to check the employee ");
return;
}
The rest of the code

CodePudding user response:

1) an1 +="' department!="" '"; What is not clear for the

BCB does not indicate that the SQL statement error at compile time, no matter the if (ComboBox1 - & gt; The Text! Please select the "=") established the SQL statements are problematic

Seems to be understandable for
If (ComboBox1 - & gt; The Text! Please select the "=")
An1 +="department='" + ComboBox1 - & gt; The Text + "'";
The else
An1 +="department=" ";


2) connection string suspected bugs, as far as possible the use of an1=an1 + "' department!="" '"; In the form of

CodePudding user response:

Track your SQL statements, may be a problem here.
If (ComboBox1 - & gt; The Text! Please select the "=")
An1 +="department='" + ComboBox1 - & gt; The Text + "'";
An1 +="' department!="" '";
This paragraph is not, don't string syntax. Single SQL syntax in the Combobox1 - & gt; The Text!="please select" when you want to what is SQL statements.

CodePudding user response:

 AnsiString strSQL="SELECT * FROM worker WHERE"; 

if (! Edit1 - & gt; Text. IsEmpty ())
StrSQL="num='+ + Edit1 - & gt;" " The Text + "' AND";

if (! Edit2 - & gt; Text. IsEmpty ())
StrSQL='" +="wname + Edit2 - & gt; The Text + "' AND";

AnsiString strXB;
If (RadioButton1 - & gt; Checked)
StrXB="male";
If (RadioButton2 - & gt; Checked)
StrXB="female";
if (! StrXB. IsEmpty ())
StrSQL +="sex='" + strXB +"' AND ";

if (! Edit3 - & gt; Text. IsEmpty ())
StrSQL +="id='" + Edit3 - & gt; The Text + "' AND";

If (ComboBox1 - & gt; Please select the "Text==")
StrSQL +="department IS NOT NULL";
The else
StrSQL='" +="department + ComboBox1 - & gt; The Text + "'";


Rewrite a bit and see if the results you want

CodePudding user response:

Compile the results and SQL Code are two happen... In order to find out the problem... Can be in the first window to temporarily join a TMemo to examine the SQL Code to distinguish whether is wrong...

CodePudding user response:

SQL is the and connection, as long as a condition is wrong, not the results
Some suggest in the SQL delete a first condition, and then query

CodePudding user response:

4th floor is truth!

CodePudding user response:

Suggest LZ will give relational database structure normalization...
Third party controls TDBGridEh have a useful STFilter project can do much to search function:

CodePudding user response:

reference 4 floor Richardw response:
 AnsiString strSQL="SELECT * FROM worker WHERE"; 

if (! Edit1 - & gt; Text. IsEmpty ())
StrSQL="num='+ + Edit1 - & gt;" " The Text + "' AND";

if (! Edit2 - & gt; Text. IsEmpty ())
StrSQL='" +="wname + Edit2 - & gt; The Text + "' AND";

AnsiString strXB;
If (RadioButton1 - & gt; Checked)
StrXB="male";
If (RadioButton2 - & gt; Checked)
StrXB="female";
if (! StrXB. IsEmpty ())
StrSQL +="sex='" + strXB +"' AND ";

if (! Edit3 - & gt; Text. IsEmpty ())
StrSQL +="id='" + Edit3 - & gt; The Text + "' AND";

If (ComboBox1 - & gt; Please select the "Text==")
StrSQL +="department IS NOT NULL";
The else
StrSQL='" +="department + ComboBox1 - & gt; The Text + "'";


Rewrite a bit, see if you want to be the result of


This is a step in the right,

What to have a look at your database field type, shaping and character type a bit but don't use=and=' '
  • Related