VB icon

Data Environment Example

Email
Submitted on: 1/5/2015 8:21:00 PM
By: Thomas D. Tomlins (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 1731
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Data Environment Example
' Description: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.
' By: Thomas D. Tomlins (from psc cd)
'
' Assumes:Must be able to get the Data Environment
'
' Side Effects:None Found
'**************************************

'IF ANYONE IMPROVES OR ADDS TO THIS CODE PLEASE FORWARD _
A COPY TO ME SO I CAN UPDATE MY RECORDS AND INTERNITE SITES _
E-MAIL: TDTOMLINS@YAHOO.COM
 
'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
 
Option Explicit
 
Private Sub Command1_Click()
On Error GoTo errorhandler
 
' To use this routine you MUST have your command _
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 your command _
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 your command _
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
 


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.