-
Visual Basic connecting to MS SQL Server
is there any way to use Visual Basic and MSSQL without using ODBC?
please let me know.
-
Visual Basic connecting to MS SQL Server (reply)
Hi,
This is to help you..... I found this script in the website DEATHMOON@HOME.COM.
I have given 4 files with the filenames and the content of that.
If you have any doubts Please ask VB Experts
All the best !!!!!
Filename: adotest.vbp
Type=Exe
Reference=*G{00020430-0000-0000-C000-000000000046}#2.0#0#C:WINNTSYSTEM32STDOLE2.TLB#OLE Automation
Reference=*G{00000201-0000-0010-8000-00AA006D2EA4}#2.1#0#C:Program FilesCommon Filessystemadomsado15.dll#Microsoft ActiveX Data Objects 2.1 Library
Form=frmADOTest.frm
Startup="frmADOTest"
Command32=""
Name="adoTest"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="x"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
Filename: adotest.vbw
frmADOTest = 44, 44, 536, 492, Z, 22, 22, 514, 470, C
Filename: mssccprj.scc
[SCC]
SCC=This is a source code control file
[adoTest.vbp]
SCC_Project_Name=this project is not under source code control
SCC_Aux_Path=<This is an empty string for the mssccprj.scc file>
Filename :frmADOtest.frm
VERSION 5.00
Begin VB.Form frmADOTest
BorderStyle = 3 'Fixed Dialog
Caption = "DSN-Less Connection"
ClientHeight = 1665
ClientLeft = 45
ClientTop = 330
ClientWidth = 3225
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1665
ScaleWidth = 3225
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtSQLStatement
Height = 285
Left = 120
TabIndex = 4
Text = "Type your SQL Statement Here"
Top = 840
Width = 3015
End
Begin VB.TextBox txtDBName
Height = 285
Left = 120
TabIndex = 3
Text = "Type your Database Name Here"
Top = 480
Width = 3015
End
Begin VB.TextBox txtServerName
Height = 285
Left = 120
TabIndex = 2
Text = "Type your SQL Server Name Here"
Top = 120
Width = 3015
End
Begin VB.CommandButton Command2
Caption = "Execute SQL"
Enabled = 0 'False
Height = 375
Left = 1800
TabIndex = 1
Top = 1200
Width = 1275
End
Begin VB.CommandButton Command1
Caption = "Open Database"
Height = 375
Left = 120
TabIndex = 0
Top = 1200
Width = 1275
End
End
Attribute VB_Name = "frmADOTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' PLEASE E-MAIL DEATHMOON@HOME.COM IF YOU HAVE
' ANY QUESTIONS / SUGGESTIONS ON THIS CODE.
' MUST REFERENCE
' MICROSOFT ACTIVEX DATA OBJECTS 2.1 LIBRARY
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Qy As New ADODB.Command
Dim sql As String
Dim ConnectionString As String
'Const ConnectionString = "driver={SQL Server};" & _
"server=PlaceServerNameHere;uid=;pwd=;database =DatabaseNameHere"
Private Sub GetConnectionString()
ConnectionString = "driver={SQL Server};" & _
"server=" & Me.txtServerName.Text & ";" & _
"uid=;pwd=;" & _
"database=" & Me.txtDBName.Text & ";"
End Sub
Private Sub Command1_Click()
GetConnectionString
With cn
' Establish DSN-less connection
.ConnectionString = ConnectionString
.ConnectionTimeout = 10
'.Properties("Prompt" = adPromptNever
' This is the default prompting mode in ADO.
.Open
End With
MsgBox "Connected"
Me.Command2.Enabled = True
End Sub
Private Sub Command2_Click()
'sql = "SELECT * FROM employee WHERE login_id='deathmoon'"
sql = Me.txtSQLStatement.Text
rs.Open sql, cn, adOpenDynamic, adLockReadOnly
MsgBox rs.Fields(0) & " " & rs.Fields(1)
rs.Close
cn.Close
End Sub
-Anu
------------
Maddleman at 8/3/01 5:08:50 PM
is there any way to use Visual Basic and MSSQL without using ODBC?
please let me know.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|