• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

SQL with VB

how we can use SQL with VB? what are the requirements for all.
0
mithunthakur
Asked:
mithunthakur
2 Solutions
 
mithunthakurAuthor Commented:
plz help me i can use SQL but not upto that much level. acctualy i want to access ODBC databases through VB. how to make connections and all plz help me
0
 
DhaestCommented:
' Easy example of using oracle as database (for sql-server, same thing to user, except the connectionstring)

dim cn as ADODB.Connection
dim rs as ADODB.Recordset

private sub form_load()

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

cn.ConnectionString = "Driver={Microsoft ODBC for Oracle};SERVER=servername;UID=username;PWD=paswoord"
cn.open

rs.open "select * from your table",cn,adOpenForwardOnly, adLockOptimistic

For example, put every field in a textbox

while not rs.eof
  text1.text = text1.text & rs.fields(0) & "-" & rs.Fields(1) & vbcrlf
  rs.movenext
wend

end sub

0
 
SethiCommented:
You will ahve to learn DAO or ADO for that. ADO is the most recommended one. The SQL statment can then be executed by using the Connection or the recordset object of ADO. Look at these links for tutorials and samples of ADO:
http://www.vbcode.com/asp/code.asp?lstCategory=Database
http://www.codeguru.com/vb/Database/index.shtml
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sherrymksCommented:
the solution suggested by dhaests  will work fine
but you may have still problems with connectio string
the easiest way to get the correct connection string is
you place an oledb data control on any form. then go to the property page for connection string
use buil option and follow the steps
so you will get the correct connection string that fits your database
0
 
CleanupPingCommented:
mithunthakur:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: Dhaest and Sethi

DanRollins -- EE database cleanup volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now