« [ASP.NET|Access] Access ����³ | �ᥤ�� | [VB.NET] DataSet��Υǡ����μ��Ф��� »
2005年10月14日
[VB.NET|Access] DataGrid ��ɽ��
Imports System.Data.OleDb
'*** Form1 Dim Conn As OleDbConnection Dim DA As OleDbDataAdapter Dim DS As DataSet Dim strSQL As String Dim DBPath As String Dim TableName As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTry '--- DB��³ Try
'1�Ԥ������طʿ������ꤹ��
DataGrid1.AlternatingBackColor = Color.FromArgb(120, 255, 255)'DB��³����
DBPath = "C:\YAMADA\�ƥ���DB.mdb"
TableName = "�桼�����ޥ���"
strSQL = "SELECT * FROM UserMst"'DB��³
Call JetConn.DB_Connect(Conn, DA, DS, strSQL, DBPath, TableName)'�ǡ�������åɤ˥ơ��֥��ɽ������
DataGrid1.SetDataBinding(DS, TableName)'���֥������Ȥγ���
Call JetConn.DB_Cut(Conn, DA, DS)Catch '--- DB��³ Catch
'���֥������Ȥγ���
Call JetConn.DB_Cut(Conn, DA, DS)
MessageBox.Show("�ͤ�����Ǥ��ޤ���Ǥ�����", "���顼�����ȥ�")End Try
End Sub
'*** JetConn.vb '----------------------------------------- ' �� DB_Connect ����DB��³ ' Conn = ���ͥ�����֥������� ' DA = �ǡ��������ץ����֥������� ' DS = �ǡ������åȥ��֥������� ' strSQL = SQLʸ ' mdbPath = Access�ѥ� ' TableName = �ǡ������åȤ����ꤹ��ơ��֥�̾ '----------------------------------------- Public Sub DB_Connect( _ ByRef Conn As OleDbConnection, _ ByRef DA As OleDbDataAdapter, _ ByRef DS As DataSet, _ ByVal strSQL As String, _ ByVal mdbPath As String, _ ByVal TableName As String)Conn = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & mdbPath)
DA = New OleDbDataAdapter(strSQL, Conn)
DS = New DataSetDA.Fill(DS, TableName)
End Sub
'-----------------------------------------
' �� DB_Connect ����DB����
' Conn = ���ͥ�����֥�������
' DA = �ǡ��������ץ����֥�������
' DS = �ǡ������åȥ��֥�������
'-----------------------------------------
Public Sub DB_Cut( _
ByRef Conn As OleDbConnection, _
ByRef DA As OleDbDataAdapter, _
ByRef DS As DataSet)If Not DS Is Nothing Then DS.Dispose()
If Not DA Is Nothing Then DA.Dispose()
If Not Conn Is Nothing Then Conn.Dispose()
End Sub
2005 / 10 / 14