سد مارب
23-09-2003, 12:40 AM
هذا كود لاستخدام طريقة الادو بالفيجوال بيسك في تصميم قاعد بينانات
اتمنى من لة خبرة كبيرة بهذه الطريقة ان يفيدنا اكثر حيث لست متقدم كثير باستخدام ADO in visual basic]
Make sure that you add the falwing References
<-- Microsoft ADO Ext. 2.6 for DDL and Security
<-- Microsoft ActiveX Data Objects Recorset 2.6 Library
<------- Form1 as Form
<------------- Text1 as TextBox
<------------- Text2 as TextBox
<------------- cmdCreaData as CommandButton
<------------- CmdCreatTable as CommandButton
Private Sub cmdCreateData_Click()
If (CreateData****(Text1.Text) = True) Then
MsgBox "Data**** Successfully Created "
Else
MsgBox "Error in Createing, Databse is not Created"
End If
End Sub
Private Sub CmdCreatTable_Click()
If (CreateAutoIncrColumn(Text2.Text) = True) Then
MsgBox "Table Successfully Created "
Else
MsgBox "Error in Createing, Table is not Created"
End If
End Sub
Function CreateData****(Data****Name As String) As Boolean
On Error GoTo TqDbError
Dim cat As New ADOX.Catalog
'Dim cat As New ADOMD.Catalog
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\" & Trim(Data****Name) & ".mdb"
CreateData**** = True
Exit Function
TqDbError:
CreateData**** = False
MsgBox "error :" & Trim(Str(Err.Number)) & " " & Err.De******ion
End Function
Function CreateAutoIncrColumn(TableName As String) As Boolean
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim col As New ADOX.Column
On Error GoTo TqTableError
' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\" & text1.text &".mdb;"
With tbl
.Name = TableName
Set .ParentCatalog = cat
' Create fields and append them to the new Table object.
.Columns.Append "ContactId", adInteger
' Make the ContactId column and auto incrementing column
.Columns("ContactId").Properties("AutoIncrement") = True
.Columns.Append "CustomerID", adInteger
.Columns.Append "FirstName", adVarWChar, 15
.Columns.Append "LastName", adVarWChar, 25
.Columns.Append "Phone", adVarWChar, 20
.Columns.Append "Salary", adCurrency
.Columns.Append "Birthdate", adDate
.Columns.Append "Notes", adLongVarWChar
End With
cat.Tables.Append tbl
Set cat = Nothing
CreateAutoIncrColumn = True
Exit Function
TqTableError:
CreateAutoIncrColumn = False
MsgBox "error :" & Trim(Str(Err.Number)) & " " & Err.De******ion
Exit Function
End Function
this code from a book is called "data**** programming in visual basic 6.0"
i hope to be good for inderstanding
your brother marib dam
اتمنى من لة خبرة كبيرة بهذه الطريقة ان يفيدنا اكثر حيث لست متقدم كثير باستخدام ADO in visual basic]
Make sure that you add the falwing References
<-- Microsoft ADO Ext. 2.6 for DDL and Security
<-- Microsoft ActiveX Data Objects Recorset 2.6 Library
<------- Form1 as Form
<------------- Text1 as TextBox
<------------- Text2 as TextBox
<------------- cmdCreaData as CommandButton
<------------- CmdCreatTable as CommandButton
Private Sub cmdCreateData_Click()
If (CreateData****(Text1.Text) = True) Then
MsgBox "Data**** Successfully Created "
Else
MsgBox "Error in Createing, Databse is not Created"
End If
End Sub
Private Sub CmdCreatTable_Click()
If (CreateAutoIncrColumn(Text2.Text) = True) Then
MsgBox "Table Successfully Created "
Else
MsgBox "Error in Createing, Table is not Created"
End If
End Sub
Function CreateData****(Data****Name As String) As Boolean
On Error GoTo TqDbError
Dim cat As New ADOX.Catalog
'Dim cat As New ADOMD.Catalog
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\" & Trim(Data****Name) & ".mdb"
CreateData**** = True
Exit Function
TqDbError:
CreateData**** = False
MsgBox "error :" & Trim(Str(Err.Number)) & " " & Err.De******ion
End Function
Function CreateAutoIncrColumn(TableName As String) As Boolean
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim col As New ADOX.Column
On Error GoTo TqTableError
' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\" & text1.text &".mdb;"
With tbl
.Name = TableName
Set .ParentCatalog = cat
' Create fields and append them to the new Table object.
.Columns.Append "ContactId", adInteger
' Make the ContactId column and auto incrementing column
.Columns("ContactId").Properties("AutoIncrement") = True
.Columns.Append "CustomerID", adInteger
.Columns.Append "FirstName", adVarWChar, 15
.Columns.Append "LastName", adVarWChar, 25
.Columns.Append "Phone", adVarWChar, 20
.Columns.Append "Salary", adCurrency
.Columns.Append "Birthdate", adDate
.Columns.Append "Notes", adLongVarWChar
End With
cat.Tables.Append tbl
Set cat = Nothing
CreateAutoIncrColumn = True
Exit Function
TqTableError:
CreateAutoIncrColumn = False
MsgBox "error :" & Trim(Str(Err.Number)) & " " & Err.De******ion
Exit Function
End Function
this code from a book is called "data**** programming in visual basic 6.0"
i hope to be good for inderstanding
your brother marib dam