Upload
warawut
View
466
Download
0
Tags:
Embed Size (px)
DESCRIPTION
ตัวอย่างการเขียนโปรแกรม VB2008 เรื่อง Connected Database with Tools
Citation preview
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
1
Connect Database with Tools
1. ��78���!� 9�$������ Microsoft Visual Basic 2008 Express Edition �������0� �.���M!$������ ! ��9
Start >>> Microsoft Visual Basic 2008 Express Edition
2. ��������$������P9����.���.��07�� Create � Project T��.�����������M!�!��� 9��07��"8 Open � Project ��"8�9�.�� �-P�4��07�� Create � Project ��78���������
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
2
3. ��78�"#����� 9����"8 2 ������V.������� New Project �P9���! �1�� ���� 9��.��07��Y�"8 Windows Forms Application �0� � 9��78�$�����! ��0�� ����5�9� 9��78� �� Condbtoots ���� 9��! OK ���� 9���Y!�`���� ! ��3� � 4. ��78�Y!�`����������������� "��!���b����7����78���7� Toolbox �07�� Common Controls --> ListBox Click �������� 9�0����Y �"8`���� ��Y!����� ListBox1! �1��
�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
3
5. ���� 9��������g� List ��78���!������� Y�"8 Toolbox �07�� Common Controls --> Button �0��0���� ���`���� " 9�.�! 3 Button ��Y!�! ��3�
�
6. ���� 9�� 9��78���g� �07��"8 Button 1 ���� "��!���� ��7��07�� Properties ---> text � 9��78� �� &List .�7� List *** ������ & !���.��� ��k������� ��0 !$!�Y�������!"8��g� List $!�����!"8��l������Y!�$!��! Shift + L Y!�" �"
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
4
7. � 9��78���g� Button �� 2 ��g�"8�.07� �.��78� �� &Clear �0���g�0�����!�78� �� E&xit �.�7�����"8 6 �� Properties ��Y!�! ��9 8. ��78������`������������0� � 9�����"#����!P��78�� �������� Student "8"#����$������ Microsoft office access ��78��#�����78�����!�� �����"#�! ��9 �07�� Data Sources --> Click Add New Data Sourcesp
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
5
9. ��78��07������ 9�����0� ������2.������� Data Sources Configuration Wizard ���� 9��07�� Database ���� 9� Next ! �1�� 10. ���� 9� Click > New Connection ������2.�������"8�78� �� Add Connection �P9���! �1�� ���� 9� Click
Change
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
6
11. ����������������.�������"8�78� �� Change Data Source �P9��������� Data Source �.��07�� Microsoft
Access Database File ��78��07���0� �s Click > OK ! �1��
12. ���� 9� Click Browse ��78�!P����"8��k� Access "8������78��� ���
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
7
13. ! �� ������07�����"8��sY �"8�78� �� Student ���� 9� Open
14. ��78��07�������������������Y!�.������� Add Connection ������ Browse ! �1������ 9� OK
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
8
15. ���� 9�������2.������� Data Sources Configuration Wizard ���� 9��.��07�� Next
16. ���� 9��.������� Microsoft Visual Basic 2008 Express Edition � 9��� �.��07�� OK
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
9
17. ���� 9�������2.������� Data Sources Configuration Wizard ���� 9��.��07�� Next 18. ���� ���� Table �.�������78��.���T3����� ���� Department ���� 9��s Finish
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
10
19. ������ 18 ��Y!�! �1������ ���� Data Sources
20. ���� 9��.����8����� ���� department Click ������2.������� Data Sources Configuration Wizard �P9����.�������78��.���T3����� ���� Table "8���� major �0� student �� � department � 9�������78��.���T3���3��0� ��79������07��Y��0� ������ 18 ���� 9� Finish
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
11
21. ���� 9��s��Y!� Data Sources �0� ��78��!���1��������2.�������"8�0 �45��9! �1�� ���������� Data Sources ���� ���� !"# ��$%�&'%(��)��*���!+�#,�
22. ��78������" 9�.�!��������0� ���� 9���� Code �.����0���g� �.������"#����$!� � 9����"81 ��� Code "8��g� List �.� Double Click "8��g�������2.�������! �1�� ���� 9���� Code ��" !"8 1 t 2 ! ��9
Option Explicit On Option Strict On
� 9����"8 2 Code ��g� List ��� Code � 9������" !"8 7 t 15 ��78���� Code ����k�! �1��
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
12
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ds As New studentDataSet '�����DataSet �����tableAdapter "8���� -�������30��. ����"��0 student ��}������30� ��DataSet ' Dim ta As New studentDataSetTableAdapters.studentTableAdapter ta.Fill(ds.student) '!P�����30����"��0 student ��}������30����s0����"��0 student �� DataSet' ' �03�� 9�����������!���TP���!"�������"��0 student �� DataSet' For i As Integer = 0 To ds.student.Count - 1 '�#�������`M0!� firstname ���8�����Y���0����0s��' ListBox1.Items.Add(ds.student(i).firstname & " " & ds.student(i).lastname) 'ListBox1.Items.Add(ds.student(i).firstname) Next 23. ��� Code �.�� ��g� Clear �.������"#����$!���� Code ! ��9 Double Click "8��g�������2.�������! �1�� ���� 9���� Code ��" !"8 19 ! ��9������2! �1��
ListBox1.Items.Clear()
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
13
24. ��� Code �.�� ��g� Exit �.������"#����$!���� Code ! ��9 Double Click "8��g�������2.�������! �1�� ���� 9���� Code ��" !"8 19 ! ��9������2! �1�� Application.Exit()
25. ��78���� Code �.�� ��g����0���g���������0� � 9������T Run $������������2�P9����0���78��!��g� List .�7� Shift + L � 9� �s�������78�� �-P�4��P9������� �"8 2
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� �
� !"#�$!� 51282792031 ����� ��-�� ��� �.�/��� � �.� �"��0 ����1 2� �!���� -3�����45�$0�
14
26. �0���78��!��g� Clear .�7� Shift + C �� �"8 2 �s��T3�0Y�! �1�� *** .���������������$�����������!��g� Exit .�7� Shift + x