Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
seefrank
Starting Member
3 Posts |
Posted - 2002-03-04 : 16:47:17
|
| Hi All, Im wondering if any one knows of a website or has any advice on how to get started making a VB form that connects to a SQL server database. All things being as simple as possible for a beginner.Thanks in advanceCasey |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-04 : 17:33:53
|
Here's the steps - Step 1.Create or open a vb project - you will be given Form1. Place a button "cmd1" and text box "text1" onto your form. Go to the code window for "cmd1".Step 2.From the Project menu, choose references, and turn on Microsoft ActiveX Data Objects 2.6 (or an earlier version)Step 3.Paste in the following code: (there are many variations....)Dim cnDB as ADODB.ConnectionDim rst as ADODB.RecordsetDim sProvider as StringDim sSQL as String'SpecificssProvider = "Provider=sqloledb;Driver=SQL Server;Server=SERVER_NAME;Database=DB_NAME;Trusted Connection=yes;"sSQL = "Select name from sysobjects"'instantiate objectsSet cndb = New ADODB.Connectioncndb.Open sProvider'send SQLSet rst = New ADODB.Recordsetrst.Open sSQL, cnDB'get data from recordset objectDo While NOt rst.EOFtext1.text = rst.Fields("name")rst.MoveNextLoop'Close objectsrst.ClosecnDB.Close'release memoryset rst = NothingSet cndb = NothingStep 4. You'll need to modify the sProvider value substituting in your SERVER_NAME and DB_NAME. I've also assumed you'll be using integrated security under NT - which assumes you have permissions to connect as you. If this is not the case- get back to me.Step 5. Change the SQL to be whatever you want - ie "select COLUMN from TABLE where OTHER_COLUMN = VALUE " etc etcNote - I've iterated through the recordset to show you how it's done. When you run this code - you'll only see the last record - but hey - if you've got that far you should be happy!!! --I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
seefrank
Starting Member
3 Posts |
Posted - 2002-03-04 : 19:33:12
|
| Thank you very much |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-04 : 19:38:27
|
my pleasure... get back to me if you need more info.... --I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|