Summarize the problems encountered in the student management system (1)

Source: Internet
Author: User

Our learning is I + 1, a little learning, a little progress, not in a hurry, one step at a time, just like learning VB during the winter vacation last year, then let's implement it by ourselves -- a small piece of software at the 9-phase High-shift Exhibition is the fruits of my harvest, and we recall that our winter vacation was so full, this summer is no exception. We have designed learning for English Sb AND database. After reading the video from instructor Yan jianling, after knocking on five instances, we got into touch with the student management system. Instructor Yan jianling had more theories in the video, so let's try again, understanding is more thorough.

After obtaining the student management system template, let's call the program first. Let's take a look at the features in the template and draw the contact between them. Then we are ready to start making the template by ourselves, basically, each of my forms has a problem. Although it is called for a form, however, when I run all the forms, the corresponding problem occurs again. Below are three of the problems I encountered.


1. login interface

The problem here is that when I enter the user name and password, if you enter the correct one, you can smoothly enter the system, but if you accidentally enter the wrong one, the program will be paralyzed, why? Please help me find a solution. Thank you.


2. Date)


At first, I thought the code was wrong. The function was useless or the format was wrong. This is part of the code of the time function.

If not isdate (txtborndate. Text) Then msgbox "Date of birth should be in the date format (yyyy-mm-dd )! ", Vbokonly + vbexclamation," warning "txtborndate. setfocus else txtborndate = format (txtborndate, "yyyy-mm-dd") if not isdate (txtrudate. text) Then msgbox "Enter the date format (yyyy-mm-dd )! ", Vbokonly + vbexclamation," warning "txtrudate. setfocus else txtrudate = format (txtrudate, "yyyy-mm-dd") txtsql = "select * From student_info" set MRC = executesql (txtsql, msgtext) MRC. addnew MRC. fields (0) = trim (txtsid. text) MRC. fields (1) = trim (txtname. text) MRC. fields (2) = trim (combosex. text) MRC. fields (3) = trim (txtborndate. text) MRC. fields (4) = trim (comboclassno. text) MRC. fields (5) = trim (txttel. te XT) MRC. fields (6) = trim (txtrudate. text) MRC. fields (7) = trim (txtaddress. text) MRC. fields (8) = trim (txtcomment. text) MRC. update msgbox "Student Status information added! ", Vbokonly + vbexclamation," add student status information "MRC. Close me. Hide end if

After reading the code and reading the data I entered, I did not find any errors. What's wrong with this?

Is there a logic problem when the code is not incorrectly added? I wrote the date of birth later than the time when I entered the school. A corresponding error is prompted, but I cannot see which code plays this role, it seems that there are still loopholes in the design. When I asked ghahan, I suddenly realized that there was indeed a problem with the input information. I entered a date that was not within the datetime range in 1345, so an error was prompted.

From the database, we can see that two date functions belong to the datetime type.

Datetime is defined in this way. The datetime data type is used to store the combination of date and time. It can store all the dates and times between on January 1, January 1, 1753 AD and on January 1, December 31, 8888 AD. The year I entered is not in this range, so an error occurs. The problem is that simple, but it will make you unable to afford it when you are careless.

When solving the problem, I also learned that the other two functions are also used in the use of SQL Server, but they are not commonly used. I 'd like to share them with you for future use,

1> isnumeric (expression)

-- Return Value: 1 | 0, which indicates whether it is a number. Numeric types include int, bigint, smallint, tinyint, numeric, money, smallmoney, float, decimal, and real)

Example:

Select * From tablename

Where isnumeric (columnname) <> 1;

Go

The preceding example uses isnumeric to return all non-numeric data rows.

2> isdate (expression)

 

-- If expression is a valid value of date, time, or datetime, 1 is returned; otherwise, 0 is returned. Example:

If isdate ('2017-05-12 10:19:41. 123') = 1

Print 'valid date'

Else

Print 'invalid date'

The preceding example uses isdate to test whether a string is a valid datetime.

3> patindex ('% pattern %', expression)

-- Returns the starting position of a mode that appears for the first time in the specified expression. -- if this mode is not found in all valid text and character data types, zero is returned.

'Pattern': a wildcard string. Before and after a pattern, it must contain % characters (except when the first or last character is searched ). Expression: it is usually a string data type column in which you want to search for the specified mode. Example:

Select patindex ('% BB %', 'aa _ bb_cc_dd_aa_bb_cc_dd ')

-- Return: 4 the above example returns the starting position of the first 'bb.

In fact, the charindex function can also be used to implement the query in the preceding example, as shown below:

Select charindex ('bb ', 'aa _ bb_cc_dd_aa_bb_cc_dd ')

-- Return Value: 4

 

Differences between the patindex function and charindex function: selectpatindex ('% [0-9] [A-Z] %', 'aa _ bb_9c_dd_aa_9f_cc_dd ')

-- Return Value: 7

Select charindex ('% [0-9] [A-Z] %', 'aa _ bb_9c_dd_aa_9f_cc_dd ')

-- Return Value: 0? The patindex function can use wildcards, but the charindex function cannot. That is to say, the patindex function is more powerful!


3. Data



When I add the class information, I immediately modify the information. When I click the last record button, the added information is not displayed.



Because I set the shift numbers in ascending order, it is normal that the last one is correct. I thought it was a problem connecting to the database, what I understand is that the original data in the database can be displayed when the system is running, but the newly added data cannot be displayed. I asked the dual-producer question that this is not the reason, because there are data sets written in the Code, the data should be updated. Then, we open the system and check that the data is not displayed in the last record, in the database, the inserted data is arranged in ascending order and should appear in the last one. Then I delete all the data and add the data again, then this time, it will be normal. In the ascending order set by me, it should be because of the data problems I added earlier.

The problems that I encountered are not a big problem. They can be attributed to carelessness and carelessness. However, these problems will make you unable to cope when you encounter them, so I am warning myself here, and I hope that you will not make such mistakes if you take me as the precaution.

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.