 |
|
 |
aak_neo Level: Scholar

 Registered: 11-02-2007 Posts: 30
|
Re: db data -->vb in one by one data (using text botton in vb)
there is code in vb for adding new records to db, EDITING AND DELETING BUT I DIDN'T understand save, preview.also tell me what way u r using to connect is it adodc control or connection & recordset object at run time.
assuming u r using conn & recordset object i m giving this foll. examples,
Command Clauses Predicates Operators Aggregate Functions
Create From Distinct AND Avg
Drop Where Top OR Count
Alter Group By NOT Sum
Select Having Between Max
Insert Order By Like Min
Update In
Delete
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!
Select
This is the most basic command which tells VB which fields to show in the recordset.
Delete
Simple, but very powerful means of deleting many records at one time.
From
Defines the Table from which the fields will be extracted.
Where
Precedes the conditions by which records are selected from the database
Order By
Sorts the records by any combination of fields you chose.
To start with you need to create a few variables of the following types
Workspace ADODB.Connection - This is required if you are using Transaction Processes (I will explain later)
Database - This connects to the database Recordset
ADODB.Recordset - This is the table/query level variable
Field ADODB.Field - This allows us to get info about the fields
Connecting to a Database
Dim ad as ADODB.Connection
set ad=New ADODB.Connection
Let ad.ConnectionString= "ODBC;DSN=" & DatabaseName & ";UID=" &
UserName & ";PWD=" & UserPassword
ad.Open
Opening a Table/Query for Viewing
dim ar as ADODB.recordset
set ar=new adodb.recordset
ar.open {SQL Statement}
do while not ar.EOF
'Put the code here for what to do with the information.
'The field information can be access by the field name
intID=ar!IDField
'Or by the order number it is in the list (starting at 0)
intString=ar.Field(1).value
ar.movenext
loop
Change a Record
dim ar as ADODB.recordset
set ar=new adodb.recordset
ar.open {SQL Statement}
ar.execute "INSERT INTO tb(ID,Name) VALUES (10,Anne)"
ADO - Add new record
dim ar as ADODB.recordset
set ar=new adodb.recordset
ar.open {SQL Statement}
ar.addnew
ar!ID=intID
ar!Name=strName
ar.update
ADO - Edit Record
dim ar as ADODB.recordset
set ar=new adodb.recordset
ar.open "SELECT * FROM Tb WHERE tdID=10"
if ar.eof then
ar.addnew
else
ar.edit
end if
ar!ID=intID
ar!Name=strName
ar.update
ADO - Delete Record
Dim ar as ADODB.recordset
set ar=new adodb.recordset
ar.open "SELECT * FROM Tb WHERE tdID=10"
if not ar.eof then
ar.delete
end if
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
For adodc control, refer
http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial3/index.html
it helped me will help u too. try looking at as many examples on both ways of linking to db conn object method is generally preferred although adodc control is much simpler
____________________________
You never see past the choices you don't understand
|
|
20-03-2007 at 02:38 PM |
|
|
axcel-trigger21 Level: Graduate
 Registered: 12-03-2007 Posts: 10
|
Re: db data -->vb in one by one data (using text botton in vb)
thanks, i will try to study this,because as i've said im just new only using visual basic.....thank you very much.....can i i message you in private if i need some help?
thanks,,,and GOD BLESS!!!
____________________________
axcel-trigger21
|
|
21-03-2007 at 08:06 AM |
|
|
axcel-trigger21 Level: Graduate
 Registered: 12-03-2007 Posts: 10
|
Re: db data -->vb in one by one data (using text botton in vb)
i study your saple code...but i think...im not using that same...
im sorry im just only new using vb express edition 2005.... the connection is like this...
dataset
sourcebinding....something like that......
____________________________
axcel-trigger21
|
|
21-03-2007 at 04:58 PM |
|
|
|
|
 |
 |