Connectivity of SQL 2000 + VB using ODBC

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #11
Apr 12th, 2008
Hi Sonia, first of all this is a personal request from me to you....don't call me like Hey choudhary....it becomes better if you use Hey Shouvik....ok..

now find your answers inline.

Originally Posted by sonia sardana View Post
Hey choudhary,
Names I have mentioned below are all used to connect to VB or not??
ADO,RDO,ODBC,DAO,OLE DB????
Yes, you are quite right. Actually there are physically three connection types available and those are :- RDO,DAO,ADO. The ADO/ODBC/OLEDB refers to same thing which is ADO (Activex Data Objects).

DAO (Data Access Objects) is used to connect to local databases such as an ms-access database.

RDO (Remote Database Objects) was used to connect to remote database objects. this sounds too spooky. actually remote database means connecting to a database which resides on some other server/node/machine other than the machine from where the vb6 application is running but both are in the same network. this was used in LOCAL AREA NETWORK protocols. it had so many limitations. for this microsoft abandoned further improvements on this technology and it was gone. after this ADO comes into the picture which overcomes all limitations of RDO along with DAO and has more features. using ADO you can connect to any databases regardless of its locations such that it can reside in a server node or in the local machine.

Originally Posted by sonia sardana View Post
AnyMore methods are there to connect to VB??
Plz just give the names as above.
No, there are no such connections method available other than these three.
I think the previous line has its answer.

Originally Posted by sonia sardana View Post
To connect to ODBC--we require DSN Connection. Right or Wrong?
To connect to OLEDB--we reruire OPEN Connection. Right or Wrong?
yes, to connect an ODBC data source a DSN connection is required. In ODBC connection, you don't require any middle tier control for linking a connection from your vb6 application to the database. just adding the reference Microsoft Activex DataObjects will do the job. after creating the connection use the ADODB objects for data interaction.

There is no connection type "OPEN". "Open" is a method of ADO connection object which creates an active connection to the database with the parameters passed in the connection string. In case of OLEDB, using DSN connection is optional. you can also use a DSN-Less connection . In OLEDB, if you want to use a DSN-Less connection you can use the ADODC control (Microsoft ADO DataControl (OLEDB).

Originally Posted by sonia sardana View Post
Can u plz give me just one-line short descriptions abt the others.
As RDO is not used today any more, further discussion on it becomes absurd. so, i'm skipping it.
Now if you use DAO technology, the coding is different. here is a sample DAO code for you. this is for opening a connection and referencing a table as a recordset object. Now you are familier with VB.Net and might you have used Dataset in your vb.net coding. In vb6 we have Recordset which performs like Dataset in vb.net. only diff. lies in their connection behaviour. as dataset can work on disconnected environment, recordset works on connected environment only.

for this code you need to add the following reference :-
Microsoft DAO <version no.> Objects Library
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim db as Database
  2. Dim rs as Recordset
  3.  
  4. set db=OpenDatabase("c:\mydatabase.mdb", False, False, ";pwd=mydatabasepassword")
  5. set rs=db.OpenRecordset("mytablename",dbOpenTable)
  6.  
  7. if rs.RecordCount>0 then
  8. rs.MoveFirst
  9. else
  10. Msgbox "Please add some records..."
  11. end if


Originally Posted by sonia sardana View Post
Second thing,The coding given by you to yogesh as scrap,In that method we are connecting using which method???
is that ADO or RDO or DAO.
the method is ADO.

hope you like my answers.

regards
Shouvik
Last edited by choudhuryshouvi; Apr 12th, 2008 at 2:54 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #12
Apr 12th, 2008
Hey Shouvik ,I like the answers.

One thing told me Suppose I learn just one connection to connect to Vb,As there are may ways to connect to VB, In companies there is any restriction that to connect using this particular method.
Suppose as we have in ASP.Net,
Like some companies require ASP with VB,
ASP with C#,
ASP with J#.

The ADO/ODBC/OLEDB refers to same thing which is ADO (Activex Data Objects).
Secondly,told me that even they are refer to the same thing,Steps are different na to connect to the database. THirdly,ADO/ODBC/OLEDB can be connect to remote or local database.Rite??

CAN We call these ADO,DAO.....as DATA ACCESS COMPONENTS.

DAO can be used to connect to local database such as MS-Access. IT means we cannot connect with SQL using DAO.Rite??

In Vb.Net we use dataset in case Of DATAGRIDVIEW. But ib Vb why v use RECORDSET HERE.
Last edited by sonia sardana; Apr 12th, 2008 at 3:41 am.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #13
Apr 12th, 2008
ok....here are your answers...

1. well, there is nothing to say about. this is completely depend upon the company policy. but as i have seen most of the companies now use ADO techniques from vb6. in my office i'm using ADO methods. you are quite right. the company management may have some project restrictions. like in the project which i'm working on, has restrictions to use the ADO technology only.

2. not too much difference you will found in the connection techniques whether you use ADO/ODBC/OLEDB. the diff. can be while you connecting to the database but the rest of the methods/properties for further database manipulations will be same. now whichever method is use there is a common thing in all of these......they all use Microsoft Activex Data Objects Library.

3. yes, ADO/DAO is known as MDAC (Microsoft Data Access Components)

4. yes, 100% correct. you cannot use DAO to connect to a sql database. you have to use ADO for this purpose.

5. not only the case of datagridview. you have to use the dataset class for data manipulations (inserting,updating,deleting,searching...etc..). in vb6 we use Recordset just for this purpose. the recordset must be used here because there is no concept of dataset i visual basic 6.

hope this helps....
any more questions.....just put it right here...

regards
Shouvik
Last edited by choudhuryshouvi; Apr 12th, 2008 at 3:46 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #14
Apr 12th, 2008
The ADO/ODBC/OLEDB refers to same thing which is ADO (Activex Data Objects).
Secondly,told me that even they are refer to the same thing,Steps are different na to connect to the database. THirdly,ADO/ODBC/OLEDB can be connect to remote or local database.Rite??

Thx Shouvik ,I m facing so much of difficulty raegarding connections,U Sort all my probs.
THX Very Much Again.
Last edited by sonia sardana; Apr 12th, 2008 at 3:47 am.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #15
Apr 12th, 2008
answer to your first and second questions i have already given in my previous reply.
just read it carefully.

and for your third question, the answer is yes.

and one more thing, please start your own thread instead of equipping in some other's thread. this will help other people to easily get their answers having same problem like you.

hope you will accept this request.

next time i wanna see you in your own thread...
ok...you are most welcome...

regards
Shouvik
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #16
Apr 12th, 2008
I will.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #17
Apr 12th, 2008
INSERTION CODE PROVIDED BY YOU IN THE PREVIOUS REPLIES-Dim rs as New ADODB.Recordset

if rs.state=adStateopen then rs.close
rs.open
"select * from branch_details",gcn,1,2
rs.AddNew
rs!branch_id=txtID.text
rs!branch_name=trim(txtName.text)
rs!address=trim(txtAddress.text)
rs.Update
if rs.state=adStateopen then rs.close
set rs=nothing

Msgbox "New record added."

Hey Shouvik ,
1) In VB,there is no insert ,update,delete statements as in VB.net.

2)In Vb.net cmd.execute Nonquery() ,& in VB rs.Update does the same job here.

3) "select * from branch_details",gcn,1,2
What does the above line means ,Can u explain dat. We have to insert the records into the DataBase,Y we r selectiong it. Epecially what does 1,2 means here.


4)
rs!address=trim(txtAddress.text)
In the above line,If I m not wrong,Address is the column name in database.

5) What does rs.AddNew means.

I think so VB.net is more easy thab VB.isn't it?
Last edited by sonia sardana; Apr 12th, 2008 at 8:59 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #18
Apr 12th, 2008
Hi Sonia,

Originally Posted by sonia sardana View Post
[B]1) In VB,there is no insert ,update,delete statements as in VB.net.
WRONG... VB6 also supports all DML Statements
Connection Object and Command Object has Execute Method, which can be any DML statement:
  1. Dim Conn As New ADODB.Connection
  2. Conn.Open <My Connection String>
  3. Conn.Execute "Insert Into MyTable Values (1,'ABCD')"

2)In Vb.net cmd.execute Nonquery() ,& in VB rs.Update does the same job here.
yes ..

3) "select * from branch_details",gcn,1,2
they are Cursor Type and LockType respectively

What does the above line means ,Can u explain dat. We have to insert the records into the DataBase,Y we r selectiong it. Epecially what does 1,2 means here.

5) What does rs.AddNew means.
Telling Recordset that you are adding new Record..

I think so VB.net is more easy thab VB.isn't it?
No... Not at all
Apart from executing Insert SQL Statement, have you Tried Adding a Record with DataAdpter , DataTable and DataRow in VB.net....?


Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 538
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #19
Apr 13th, 2008
Madam Sonia,
I think Veena has already given all of your answers. So there is nothing need to say any more from my side except these,

Originally Posted by sonia sardana View Post
3)
"select * from branch_details",gcn,1,2
Can u explain dat. We have to insert the records into the DataBase,Y we r selectiong it.
in the above statement we are not selecting anything from the database. a connection/reference to the table has just been established or you can say opened so that the recordset object which is "rs" here recognize/know where to send the data when the .update method fires. here we are just setting the destination for the recordset object.

Originally Posted by sonia sardana View Post
4)
rs!address=trim(txtAddress.text)
In the above line,If I m not wrong,Address is the column name in database.
yes, you are correct. Address is the column name. This is just one type of syntax used here. Instead of this you can also use this, rs("Address") or this rs(2)-->here 2 is the index/subscript value of the address field in the rs recordset.

Apart from this, if you still have any more questions then feel free to post here.

regards
Shouvik
Last edited by choudhuryshouvi; Apr 13th, 2008 at 4:27 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #20
Apr 14th, 2008
I have tried the foll. code- But it contains errors.plz help me out to sort it & Reply--

Private Sub Form_Load()
Dim gcn As New ADODB.Connection
gcn.Open = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=sonia"
Dim query As String


query = "Insert into stuinfo values([roll],[name],[marks]), &_"
values("& me.txtroll.Text &","& me.txtname.Text &","&me.txtmarks.Text &")
gcn.Execute (query)
MsgBox "Record Inserted"
gcn.Close
End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 5673 | Replies: 29
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC