[SQL数据操作基础]第十章“SQL基础”向你初步介绍了SQL。你学会了如何用SELECT语句进行查询,你还学会了如何建立自己的表。在这一章里,你将加深你的SQL知识。你将学习如何建立索引来加快查询速...+阅读
'加载控件:Microsoft DareGrid Control 6.0(SP6) '加载控件:Microsoft ADO Data Control 6.0(SP6)
'窗体加载控件command1(连接数据库),Adodc1,DataGrid1,Text1(数据库地址,ip,实例),Text2(用户名),Text3(密码)
Private Sub Command1_Click() Dim objcon As New ADODB.Connection Dim objrs As New ADODB.Recordset Dim strConn As String objcon.CommandTimeout = 3'设定连接命令等待时间 strConn = "Provider=SQLOLEDB.1;User ID=" & Text1 & ";password=" & Text3 & ";Initial Catalog=Mysql;Data Source=127.0.0.1"'这里使用数据库名为:MYSQL
'strConn = "Provider=SQLOLEDB.1;User ID=用户名;password=密码;Initial Catalog=数据库名;Data Source=SQL服务器IP或者机器名+实例名" on error goto l1'当数据库连接出问题时跳转至标签L1处处理
objcon.Open strConn '建立连接
objrs.Open "select * from Label1", objcon, 3, 1'SQL语句例子,这里为查询LABEL1中所有列.
Set DataGrid1.DataSource = objrs'将SQL语句执行结果显示在控件中 objcon.Close'关闭数据库
exit sub
l1:
msgbox "数据库连接错误,错误号:" & err.Number '返回错误信息,err.number是错误标号
err.Clear '清除错误记录号
exit sub End Sub
'以上用到这个两个数据库控件必须使用在安装有VB6企业版才能找到.
vb连接远程sql数据库
VB连接SQL模块。直接拿去用吧。
Public conn As New ADODB.Connection Public rs As New ADODB.Recordset Public addFlag As Boolean
Public Function OpenCn(ByVal Cip As String) As Boolean Dim mag As String On Error GoTo strerrmag Set conn = New ADODB.Connection conn.ConnectionTimeout = 25 conn.Provider = "sqloledb" conn.Properties("data source").Value = Cip '服务器的名字 conn.Properties("initial catalog").Value = "zqoa" '库名 'conn.Properties("integrated security").Value = "SSPI" '登陆类型 conn.Properties("user id").Value = "sa" conn.Properties("password").Value = "sa" conn.Open OpenCn = True addFlag = True Exit Function strerrmag: mag = "Data can't connect" Call MsgBox(mag, vbOKOnly, "Error:Data connect") addFlag = False Exit Function End Function
Public Sub cloCn() On Error Resume Next If conn.State <> adStateClosed Then conn.Close Set conn = Nothing End Sub
Public Function openRs(ByVal strsql As String) As Boolean '连接数据库记录集 Dim mag As String Dim rpy As Boolean On Error GoTo strerrmag Set rs = New ADODB.Recordset If addFlag = False Then rpy = True With rs .ActiveConnection = conn .CursorLocation = adUseClient .CursorType = adOpenKeyset .LockType = adLockOptimistic .Open strsql End With addFlag = True openRs = True End 'Exit Function strerrmag: mag = "data not connect" Call MsgBox(mag, vbOKOnly, "error:connect") openRs = False End 'Exit Function End Function Public Sub cloRs() On Error Resume Next If rs.State <> adStateClosed Then rs.Clone Set rs = Nothing End Sub
如何利用VB6 0和SQL Server访问远程数据库
可以的,给你个连接函数参考: Public Function OpenConn() As Boolean Dim sIniFile As String Dim szBuff As String * 255, nread As Long Dim SqlServer As String Dim SqlUsername As String Dim SqlPassword As String Dim SqlDatabase As String Dim nTimeout As Long Dim ConnStr As String sIniFile = App.Path + "\setup.ini" nread = GetPrivateProfileString("DATABASE", "Server", "", szBuff, 255, sIniFile) SqlServer = BuffToStr(szBuff, nread) nread = GetPrivateProfileString("DATABASE", "Username", "", szBuff, 255, sIniFile) SqlUsername = BuffToStr(szBuff, nread) 'SQL数据库用户名 nread = GetPrivateProfileString("DATABASE", "Password", "", szBuff, 255, sIniFile) SqlPassword = BuffToStr(szBuff, nread) 'SQL数据库用户密码 SqlPassword = DECode(SqlPassword) 'SqlPassword = "wang" nread = GetPrivateProfileString("DATABASE", "Database", "", szBuff, 255, sIniFile) SqlDatabase = BuffToStr(szBuff, nread) 'SQL数据库名 nTimeout = GetPrivateProfileInt("DataBase", "Timeout", 600, sIniFile) On Error GoTo ErrorConn ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabase & "; Data Source = " & SqlServer & ";" Conn.ConnectionString = ConnStr Conn.CursorLocation = adUseClient Conn.Open Conn.CommandTimeout = nTimeout OpenConn = True Exit Function ErrorConn: OpenConn = False End Function
如何在VB6中连接远程的数据库
最近测试过程中,老需要远程登录到外网的一套服务器上面做测试,但是因为不少开发GG也在上面部署新的代码,所以互相T来T去的,着实比较痛苦和纠结。。今天终于找到一个临时的解决办法,就是偶在万不得已的情况下再远程登录,如果只涉及数据库操作(测试数据查询,修改等),可以在本地连接服务器上面的数据库。1.安装putty,plink(最好放到C:\Documents and Settings\administrator目录下)2.如果在安装在其他目录下,从命令行进入 putty.exe 所在的目录3.在命令行执行 plink -L 50081:192.168.0.***:1433 -l dev -pw mozat 210.193.**.***(这条命令是映射本地端口50081 到192.168.0.***:1433)4.打开sql servermanagement studio,输入服务器:127.0.0.1,50081,数据库用户名/密码,连接即可5.然后在另一个命令行窗口中执行 mstsc /v:localhost:1433 /admin 即可进行远程登录其中1433是连接默认的那个数据实例,可按需更改你需要连接的数据实例;50081可以随便使用,尽量用大一些,以免和其他的冲突,当然不要大于6W多就好这样就不要远程登录到服务器才能进行数据库操作了。
...
以下为关联文档:
VB操作数据库新手求指点Private Conn As New ADODB.Connection Private RS As New ADODB.Recordset private strConn as String strConn=" Con=Provider=SQLOLEDB.1;Password= ;Persist Security In...
如何利用Access链接远程SQL数据库以windowsxp+Access2003+sqlserver2000为例: 一、建立ODBC数据源: 1、打开控制面板\管理工具 2、运行数据源 (ODBC) 3、选择“用户DSN”标签页 4、点击添加按钮,选择SQL Server、...
VB怎么实现访问远程access数据库这是网络编程 远程要有客户端(或服务端)程序的,如果没有远程程序作支持,一般会被对方防火墙、安全策略、服务等设置情况阻挡(除非对方是特定服务器计算机)。 访问远程access数据库...
你好!请问vb6 0中怎样远程访问access数据库在工程里引用microsoft activex data objects 2.7 library Dim cn As New ADODB.Connection, rs1 As New ADODB.Recordset, sql As String '在通用声明里定义,其中cn是连接对...
学过VB和SQL的人有谁知道如何将SQL集中的数据导出为world文档Public Sub ExportToWord(RsData As ADODB.Recordset, FileNameSaveAs As String) Dim appWord 'WORD程序对象 Dim docWord 'WORD建立新文档对象 Dim tblWord '文档中的表格...
初学VB请教VB60连接SQL数据库具体步骤Dim conn As New ADODB.Connection Dim rs(10) As New ADODB.Recordset db = App.Path & "\db\data.mdb" conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Pa...
SQL导入数据库ASP与SQL数据库连接 关键词: ASP与SQL数据库连接 <% language=VBs cript%> <% dim conn set conn=server.createobject("ADODB.connection") con.open "PROVIDER=SQLOLEDB;DATA...
数据库教程 sql怎样外网连接远程数据库要点: 1.确认服务器端SQL服务端口号是否为:1433 2.如果不是1433,配置客户端 3.建立服务器端登录帐号,确保角色及管理数据库 一、查看服务器端情况 1. 看ping 服务器IP能否ping通...
sql数据库连接你看看吧,全了 。数据库的连接方法:2. ASP与SQL数据库连接:1.Access数据库的DSN-less连接方法: set adocon=Server.Createobject("adodb.connection") adoconn.Open"Driver={Micros...