Professional Documents
Culture Documents
Nstructions
Nstructions
c
O? Database ready to attach
O? Database software installed on a PC (optional)
O? îisual Basic Express installed on a PC (optional)
O? îisual Studio.NET installed on a PC (optional)
1.? 1
Open your developer environment, then open the project you're working on. If you don't
have a project yet, create one by clicking "Create" next to "Project." A new window
opens. The SQL query will work in any of the application types, but the easiest way is to
select "Windows Form Application". Type the name of your file in the "Name" box and
press "OK."
2.? 2
Navigate to the top menu bar and click on "Data." Choose "Add New Data Source."
Follow the screen prompts to add the database to your project. The box will close when
you're finished.
3.? 3
Click on "Data" again in the top menu choices. Choose "Add Query", and a new box will
open showing you the fields you created in your database. Click "Query Builder" at the
bottom. The query builder window will open.
4.? 4
Move the borders of the query-building window so you can fully see all the aspects
available to you. The top section shows your database fields. Unclick any fields you do
not want SQL query to sort. For example, if you need to find all cars made between the
years of 1976 and 1985, then unclick fields like "Motorcycles," "Trucks" or "Last Name"
because those fields are not relevant to the search.
5.? 5
Drop down to the next section to choose how you want the fields you are sorting to
display. Click "Output" if it is not already checked. Choose the "Sort Type" and "Sort
Order." The pane below shows the actual SQL query as it's created.
6.? 6
Click "Execute Query" to test it. Executing it is the same as commanding it to run, and
executing it effectually links the SQL query to your îisual Basic project. Click "OK"
when you're done.
Read more: How to Link SQL Queries With îisual Basic | eHow.com
http://www.ehow.com/how_6351860_sql-queries-visual-basic.html#ixzz1DWKDeFWw
?
î
This is not about how to create or design a database, it is about how to connect to a database and
manipulate a database using îB. It will work (with some minor alterations) in îBA as well.
There are several ways of connecting to a database (for example, Access), via data bound
controls, DAO or ADO. On the whole I do not use data bound controls because I like to keep
control of what is happening to the data so the rest is about DAO/ADO.
To start with you need to create a few variables of the following types
O? £ ?
?????? ??? ? ???
? ??
O? !??? ? ??!?" ??
O?
" ?????!#?$?$!??
O? º?
º??? ?? ?? ?! ????
With an Access database it is possible to connect to the database in 2 ways, JET or ODBC.
Personally I use ODBC because the file management is easier; to change the filename or path
just use the ODBC administrator in the control panel.
Note: These examples are here to show what to do very simply, some of the commands have
more options than are shown so please review the help files for more details.
ccc
Dim ws as Workspace
Dim db as Database
Set ws=DBEngine.Workspaces(0)
set db=ws.OpenDatabase({databasepath and name})
ccc
Dim ws as Workspace
dim db as database
dim strConnection as string
set ws=DBEngine.Workspaces(0)
let strConnection= "ODBC;DSN=" & DatabaseName & ";UID=" & UserName
& ";PWD=" & UserPassword
set db=ws.OpenDatabase("", False, False, strConnection)
Dim ad as ADODB.Connection
Now we have the database connection established it is time to look at the data. The following
example show how to open a table/query and move through it.
Dim rs as recordset
dim ar as ADODB.recordset
To edit/add/delete a record we can do it either using SQL or directly. Both DAO and ADO use
the execute method for doing updates by SQL.
Dim rs as recordset
dim ar as ADODB.recordset
Dim rs as recordset
c
dim ar as ADODB.recordset
These examples show how to edit a record directly, after the recordset is open it checks that there
is a record meeting the criteria in the open SQL. If not it creates one.
Dim rs as recordset
dim ar as ADODB.recordset
These examples show how to delete a record directly, after the recordset is open it checks that
there is a record meeting the criteria in the open SQL. If not it does not do a delete.
Dim rs as recordset
Dim ar as ADODB.recordset
Note: If you open an object when you have finished with it, close it and set it to nothing. For
example...
rs.close
set rs=nothing
J ?
?$?? ??? %??? ???&'(??&?'?(??
????????)?? ???? ? ?? ? ??
????? ? ???*?? ? ?$? ???? ??
+?!?, ??$??&'(????* ?*? ???? ?
îB has very poor documentation of its support for SQL. What SQL is or how it is used is a
mystery for most beginners simply because it is so darned hard to find out any information on
the topic! Those few references to SQL that exist in the îB documentation are very short
examples and there is virtually no discussion on how to create your own queries.
I assume that part of the reason for the Microsoft approach to SQL is that it sells a product called
SQL Server, which is a very powerful database interface. îB offers a limited set of the SQL
Server features but Microsoft doesn't highlight those capabilities, preferring instead to sell its
larger, more profitable product.
Considering the power of SQL statements I'm very surprised that Microsoft doesn't highlight the
features more than they do. However, the fact is that beginners have to look hard to find help so
that's where this tutorial comes into play.
Now that you've read some of the examples, how do you use them? Simply set the RecordSource
property of a data control to an SQL statement such as those above and refresh the control like
this:
Just make sure that any references to fields match those contained in the actual database. Doing
so will create a recordset whose content will match the constraints described by the SQL
statement.
Considering that there are entire books on this subject, I can hardly expect to do it serious justice
but there are some basics which can be summarized in a short tutorial like this one.
First of all, there are 5 parts to an SQL statement which you should recognize:
? ?
?
?
??
? £? ?
"?
??
? 8 ?? 7
? &*??
?
&? 9$? ? :??
?
?
?? (? :??
?
;? ??
? ? ?
?
? ? ? ?
With a little inspection you can pretty much guess what each of these pieces of an SQL statement
can do. However, here are a couple which you'll not want to miss and which I use pretty
regularly. Don't miss the last one in my list, which is a very easy way to sort a recordset!
O? J
?
???* ?!? **???)??? ? ??? ??
O?
?
&*%?!?$? ?*? ??*? ?? ?*??
O?
?
??!? *?????!???
O? £
?
?? ?!?? ??? *??!??
O?
?
& ?? ?!?? *! ? ?? ? ??
This should get you started. Try out a few of the examples on one of the databases which come
with îB and you'll see that it's really very easy to use the power of SQL!
Japan Post has decided to incorporate fingerprint scanning in its ATM network rather than using
palm-scanning technology, sources said Saturday.
Part of the second-phase replacement will be undertaken by the postal savings bank, a unit that
will emerge from the planned privatization of the postal system starting in October 2007.
In addition to the postal savings bank, the privatization process will create three other entities
under a holding company -- a mail service company, a postal life insurance firm and a company
to manage the nationwide network of post offices.