Connectivity of SQL 2000 + VB using ODBC

Reply

Join Date: Apr 2008
Posts: 43
Reputation: Yogesh Sharma is an unknown quantity at this point 
Solved Threads: 1
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Connectivity of SQL 2000 + VB using ODBC

 
0
  #1
Apr 7th, 2008
steps i Follow-
1) Go to Control panel-->Admintrative Tools-->Double -click
Data sources(ODBC)-->click Add button-->I choose SQL server(last option), Is it right or wrong option for connecting to SQL 2000.Then a new screen appears Create a New dataSource-->in name textbox,we can write anyname--Right or wrong. suppose i enter sonia, & my server name is .,so I enter . in server & click next button-->On the Next screen i have checked the option With Sql server authentication-->Login Id-sa, Password-->Blank-->Click next button-->Next-->Finish-->Then I click on button Test Data source-->Mesage Comes TESTS COMPLETED SUCCESSFULLY-->OK-->OK-->Ok.

These steps we have to do or not for Connectivity using ODBC.
If yes,then what after these steps we have to do??Plz reply me early ??Thx in advance.

Plz tell me the coding also for insertion of textbox values into the textbox.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
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
  #2
Apr 7th, 2008
the steps you followed for creating the DSN are absolutely correct. but there is no need to create that. it is always recommended that you use a DSN-Less connection. It becomes more faster.

ok...here is a sample connection snippet for you. please note that this code uses DSN-Less connection.
just goto Project->References and add Microsoft Activex Data Objects <Version No.> Library into your project.

''code for making a connection with the sql server database
Private Sub Form_Load()
Dim gcn as New ADODB.Connection

gcn.connectionstring="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=bs;Initial Catalog=BILLING_SYSTEM"
gcn.open
msgbox "A connection to the database is now established"
End Sub

''code for retrieving some rows from a table
Private sub Command1_Click()
Dim rs as New ADODB.Recordset
Dim str as String
Dim li as ListItem

str="select * from branch_details order by branch_id"
rs.open str,gcn,1,2

if rs.Recordcount>0 then
   rs.MoveFirst
   While not rs.EOF()
      with Listview1
         set li=.listitems.add(,,(branch_id))
         li.subitems(1)=rs!branch_name
         li.subitems(2)=rs!address
      end with
      rs.MoveNext
   Wend   
else
   msgbox "No record found." & vbcrlf & "Please add some records."
end if

if rs.State=adStateOpen then rs.close
set rs=Nothing
End Sub

look for the Bolded Parts in the connection string. the first one should be replaced by yours database user name and the second one is by your original database name.

for inserting values from textbox to your sql server database use the following code :-
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."

look into the Bolded Part. it must be replaced by your table name where you wish save your records.

hope this helps you.
try this and give me a feedback.

regards
Shouvik
Last edited by choudhuryshouvi; Apr 7th, 2008 at 3:45 pm.
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: Apr 2008
Posts: 43
Reputation: Yogesh Sharma is an unknown quantity at this point 
Solved Threads: 1
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #3
Apr 7th, 2008
hey tell me dat ADODC is always used on all the form,if we deal with the database.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
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
  #4
Apr 7th, 2008
not compulsorily.
but you can use the ADODC control.
but it is not recommended. always use ADODB objects to communicate with your databases.

in the preceding code i gave you, you don't require to have any ADODC control on your form.

ok...
tell me if any more problem arises...

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: Apr 2008
Posts: 43
Reputation: Yogesh Sharma is an unknown quantity at this point 
Solved Threads: 1
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #5
Apr 7th, 2008
There is so such control in the Components... Microsoft Active X Plug in ..Is it same as which u r saying?/I m working on 6.0.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
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
  #6
Apr 7th, 2008
you don't require that control you mentioned.

infact, you don't require any data controls from your components list to work with this code. for listview control add this ,
Microsoft Windows Common Control 6.0

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: May 2007
Posts: 537
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
  #7
Apr 7th, 2008
Originally Posted by Yogesh Sharma View Post
There is so such control in the Components... Microsoft Active X Plug in ..Is it same as which u r saying?/I m working on 6.0.
absolutely no.
you are in wrong place.

look at your menu bar inside your vb6 IDE. you will find a menu called Project.
inside it there is a command References... goto there,scroll down and add the reference
Microsoft Activex DataObjects ... Library

choose the highest version.

ok....
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: Apr 2008
Posts: 43
Reputation: Yogesh Sharma is an unknown quantity at this point 
Solved Threads: 1
Yogesh Sharma Yogesh Sharma is offline Offline
Light Poster

Re: Connectivity of SQL 2000 + VB using ODBC

 
0
  #8
Apr 7th, 2008
But nothing is added in the toolbox to which I can Drop onto the form,after doing this. As when we add ADO,it is added in the toolbox.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
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
  #9
Apr 8th, 2008
listen carefully my frnd,
Microsoft Activex Data Objects is a reference not a component or control. so it won't be added into the toolbox. each control you use on your vb6 form adds a reference to your project. now if you add an ADODC control on your form it will add the same ref. on your project too. to see this, just add an ADODC control from your component list and now go to Project->References. there you will see Microsoft Activex Data Objects has been added to your project reference list.

i'm telling you again plz read previous replies ten times before you post a reply.
in my previous replies several times i have said that this code doesn't require any control/component to be added on your form. it is using a reference and for that adding MS ADO is enough.

look into the code very carefully. there is a statement Dim gcn as New ADODB.Connection. this is a global variable which is nothing but an instance of ADODB Connection object. so to use this vars or accessing ADO methods/functions inclusion of this reference is very much important. otherwise you will face compilation errors.

hope you'll understand and approach to right direction this time.

regards
Shouvik
Last edited by choudhuryshouvi; Apr 8th, 2008 at 4:38 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
  #10
Apr 10th, 2008
Hey choudhary,
Names I have mentioned below are all used to connect to VB or not??
ADO,RDO,ODBC,DAO,OLE DB????
AnyMore methods are there to connect to VB??
Plz just give the names as above.

To connect to ODBC--we require DSN Connection. Right or Wrong?
To connect to OLEDB--we reruire OPEN Connection. Right or Wrong?

Can u plz give me just one-line short descriptions abt the others.

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.
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
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC