DataEnviron




Option Explicit

Private Sub Command1_Click()
On Error Goto errorhandler
'To use this routine you MUST have yourcommand _

'as a SQL statement and have a valid statement _

'within it.DataEnvironment1.Commands.Item("Command1").

'CommandText = Text1.Text

'You must manually rebind your datagrid to activate the

'Required commands


With DataGrid1
.DataMember = "Command1"
Set .DataSource = DataEnvironment1
End With

'You must close the recordset between commands

DataEnvironment1.rsCommand1.Close
Exit Sub
errorhandler:
Call errorRoutine
Resume Next
End Sub

Private Sub Command2_Click()

'Valad Tables: Titles, Publishers, Authors, 'Title Author'

'NOTE: you must put single ' around Title Author.


On Error Goto errorhandler
'To use this routine you MUST have yourcommand as a

'DataObject statement and have a valid Object and _

'Object name within it.


DataEnvironment1.Commands.Item(2).CommandText = Text2.Text

'You must manually rebind your datagrid to activate the

'Required commands


With DataGrid1
.DataMember = "Command2"
Set .DataSource = DataEnvironment1
End With
'You must close the recordset between commands

DataEnvironment1.rsCommand2.Close
Exit Sub
errorhandler:
Call errorRoutine
Resume Next
End Sub

Private Sub Command3_Click()
On Error Goto errorhandler
'To use this routine you MUST have yourcommand as a SQL

'statement and have a valid statement within it. Use the ?

'To indicate the Paramater. Make sure your Parameter

'settings are correct.


DataEnvironment1.Command3 Text3.Text
'You must manually rebind your datagrid to activate the

'Required commands

With DataGrid1
.DataMember = "Command3"
Set .DataSource = DataEnvironment1
End With
'You must close the recordset between commands

DataEnvironment1.rsCommand3.Close
Exit Sub
errorhandler:
Call errorRoutine
Resume Next
End Sub

Private Sub errorRoutine()
MsgBox ("You must have appropriate commands In the textbox")
End Sub

Private Sub Command4_Click()
DataReport1.Show
End Sub

Private Sub Form_Load()
MsgBox "Valid Tables: Titles, Publishers, Authors, _
'Title Author'"

'NOTE: you must put single ' around Title Author."

Label1.Caption = " Enter SQL statement"
Text1.Text = "Select * From Titles"
Command1.Caption = "Run SQL statement"
Label2.Caption = "Enter Table Name"
Text2.Text = "Authors"
Command2.Caption = "Run Table Statement"
Label3.Caption = "Enter Year To search Publisher"
Text3.Text = "1985"
Command3.Caption = "Run Paramater Statement"
End Sub Assumes:Must be able to get the Data Environment

'DataEnvironment is one item that is hard to find _

Detail information about how To use it. I truly _
Believe VB's DataEnvironment is the way To go _
But using it takes time. This program will go _
over some way's To make your data-environment more _
Flexable during run-time operations that is Not _
usually covered In the majority books available To users.

When making changes be sure the Table,Field,Record is
within the database.
Open a dataproject if you already have a form open
Then you will have To add a DataEnvironment To your
project within data environment make a connection to
Biblio.mdb (comes With VB usually In dir
C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb
Create a command Add an SQL statement:

Select * from Authors
Create another command add a Data object-Database as
TABLE Object will be TITLES.
Create a another command add a SQL statement: _

Select Titles.* FROM Titles WHERE (`Year Published` = ?) _
In the Paramaters Tab Set DATA Type as SMLINT and _
Set HOST DATA Type as INTEGER.

ON THE FORM ADD THE FOLLOWING
Add To the from a DataGrid, Three CommandButtons, _
Three Labels With TextBox For Each










( dataenviron.html )- by Paolo Puglisi - Modifica del 17/12/2023