Data room charging system-Combined Query

Source: Internet
Author: User

When I typed a Combined Query, I encountered a lot of problems, such as how to connect the query syntax, how to make the text information in the control that is, the field name, and the combination relationship correspond to the fields in the database table?

That is to say, we need to make the card number = cardno and the name = studentname, so that we can easily query it. Instead, we can't directly give the text in combox English? Define a function to implement this function. The function is as follows.

<Span style = "font-size: 18px;"> Public Function Field (I as string) as string select case I case "card" field = "cardno" case "name" field = "studentname" case "" field = "ondate" case "field" field = "ontime" case "down date "....... end selectend function </span>
That's all. The combined query syntax and code below

<Span style = "font-size: 18px;"> private sub cmdinqurie_click () dim CTRL as control dim MRC as ADODB. recordset dim txtsql as string dim msgtext as string 'Check condition input if trim (cmbfeild1.text) = "" or trim (cmboperator1.text) = "or trim (txt1.text) = "" Then msgbox "Enter the full query condition", "prompt" Exit sub end if Dim I, icols as integer 'align all columns with the text icols = msflexgrid1.cols for I = 0 to icols-1 msflexgrid1.colalignmen T (I) = flexaligncentercenter next txtsql = "select * From line_info where" txtsql = txtsql & trim (field (cmbfeild1.text) & trim (cmboperator1.text )) & "'" & trim (txt1.text) & "'" If trim (cmbrelation1.text <> "") then' first composite relationship if trim (cmbfeild2.text) = "" or trim (cmboperator2.text = "") or trim (txt2.text = "") Then msgbox "you have selected the first composite relationship. Enter the query condition of the second row ",, "prompt" Exit sub else txtsql = txtsql & field (T Rim (cmbrelation1.text) & "" & field (cmbfeild2.text) & cmboperator2.text & "'" & trim (txt2.text) & "'" end if trim (cmbrelation2.text <> "") then' second composite relationship if trim (cmbfeild3.text) = "" or trim (cmboperator3.text) = "" or trim (txt3.text) = "" Then msgbox "you have selected the second composite link. Enter the third row query condition ",, "prompt" Exit sub else txtsql = txtsql & field (cmbrelation2.text) & "" & field (cmbfeild3.text) & cmboperator3. Text & "'" & trim (txt3.text) & "'" end if on error goto error1 'error statement protection. A prompt message is displayed when the format of the query is incorrect. Set MRC = executesql (txtsql, msgtext) If MRC. EOF = true then 'check whether the information exists. If the prompt does not exist and all text boxes are cleared msgbox, the information you entered may not exist, or information conflict "for each CTRL in me. controls if typeof CTRL is textbox then 'Whether it is textbox ctrl. TEXT = "" 'clear all text boxes end if next for each CTRL in me. controls if typeof CTRL is ComboBox then 'is the textbox ctrl. TEXT = "" end if next exit sub end if with msflexgrid1. rows = 1. textmatrix (0, 0) = "Card number ". textmatrix (0, 1) = "name ". textmatrix (0, 2) = "computer date "........ do while not MRC. EOF. rows =. rows + 1. textmatrix (. rows-1, 0) = trim (MRC! Cardno). textmatrix (. Rows-1, 1) = MRC! Studentname. textmatrix (. Rows-1, 2) = MRC! Ondate. textmatrix (. Rows-1, 3) = MRC! Ontime ...... MRC. movenext loop end with MRC. closeerror1: msgbox "the query information you entered is incorrectly formatted. Enter the Information in the standard format. "End sub </span>

There are a lot of code. The final idea here is how to break through our inherent thinking, how to innovate, and how to instill our thoughts. We need to use the knowledge we have learned before to achieve the effect of learning and using, in fact, there are more simple and practical code than this write for our development, research.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.