943,763 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Apr 7th, 2008
0

Connectivity of SQL 2000 + VB using ODBC

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Yogesh Sharma is offline Offline
43 posts
since Apr 2008
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

hey tell me dat ADODC is always used on all the form,if we deal with the database.
Reputation Points: 10
Solved Threads: 1
Light Poster
Yogesh Sharma is offline Offline
43 posts
since Apr 2008
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
Yogesh Sharma is offline Offline
43 posts
since Apr 2008
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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....
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 7th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
Yogesh Sharma is offline Offline
43 posts
since Apr 2008
Apr 8th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Apr 10th, 2008
0

Re: Connectivity of SQL 2000 + VB using ODBC

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.
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help with Login scree developed in visual basic 6.0
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Creating Alert in Vb.6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC