這裏有一個快速的東西給你來啃。 我爲您創建了表格,並對您的示例數據進行了插入,即使表格結構您可以及時瞭解更多信息。
至於創建表的列名,嘗試從未使用保留字,甚至函數,可能會引起混淆的道路......這種在這種情況下,「類」,「日」。在編碼時,您會看到保留字通常以藍色語法顏色顯示。如果你在創建表格的時候再想一想這個專欄的名字更好。
至於VFP列名。如果表格不是「數據庫容器」的一部分,那麼列名稱限制只有10個字符(所以我將「Lesson_Name」更改爲「LessonName」)。
我這樣做樣本與簡單的SQL查詢。在VFP vs其他sql數據庫中查看的差異相對較小。一件大事就是在VFP中,分號表示命令CONTINUES在下一行。在SQL中,分號通常表示命令的結束。
*/ Sample... create the tables and insert the values
SET SAFETY OFF
CLOSE TABLES ALL
CREATE TABLE Classes;
( Class C(3),;
Day N(1),;
Lessons C(7))
INSERT INTO Classes (Class, Day, Lessons);
VALUES ("IX", 1, "MEP")
INSERT INTO Classes (Class, Day, Lessons);
VALUES ("X", 2, "MBE")
INSERT INTO Classes (Class, Day, Lessons);
VALUES ("XI", 3, "FCM")
*/ Create the next table and insert their records
CREATE TABLE Lessons ;
( Lesson C(1),;
LessonName C(10))
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("M", "Math")
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("E", "English")
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("B", "Biology")
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("F", "French")
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("P", "Physics")
INSERT INTO Lessons (Lesson, LessonName);
VALUES ("C", "Chemistry")
*/ Prepare a look and keep asking until a user hits the escape key (ASCII 27)
DO WHILE LASTKEY() <> 27
*/ prepare a value for data entry of the class
SomeClass = " "
@ 1,1 say "Enter a value for a class (escape or leave blank to exit):" get SomeClass picture "!!!"
READ
IF EMPTY(SomeClass)
EXIT
ENDIF
*/ Query the classes table for the value entered
USE IN SELECT("FoundClass")
SELECT Class, Day, Lessons;
FROM Classes;
WHERE Class = SomeClass;
INTO CURSOR FoundClass READWRITE
*/ Did we find the class?
IF RECCOUNT("FoundClass") = 0
MESSAGEBOX("Sorry, class was not found")
ELSE
*/ Now, get all lessons associated with the class.
USE IN SELECT("FoundLessons")
SELECT Lesson, LessonName;
FROM Lessons;
WHERE Lesson $ FoundClass.Lessons;
INTO CURSOR FoundLessons READWRITE
IF RECCOUNT("FoundLessons") = 0
MESSAGEBOX("Sorry, no lessons found for the class")
ELSE
CLEAR
?
?
?
? "Class: " + FoundClass.Class, ;
" Day: ", FoundClass.Day, ;
" Lessons: " + FoundClass.Lessons
? "Lessons:"
SELECT FoundLessons
SCAN
? FoundLessons.LessonName
ENDSCAN
ENDIF
ENDIF
USE IN SELECT("FoundClass")
USE IN SELECT("FoundLessons")
ENDDO
CLEAR
在學習初期,開始有良好的表結構......所有的表應該有一個主鍵ID一起工作。不要使用一列的子字符串作爲基礎來加入另一列。爲主題分類創建一個新列。另外,列出您的示例數據。最後,你是用一個簡單的PRG來做這件事,還是你正在創建一個窗體並在窗體上放置文本框和命令按鈕來處理。 – DRapp
我正在嘗試使用簡單的prg和基本命令。 – user3105150