如何连接到SQL SERVER数据库,以及如何打开表

chuting1 2002-05-05 01:32:22
如何连接到SQL SERVER数据库,以及如何打开表
请用多种方法,ADO或DAO或更多
...全文
181 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuting1 2002-05-07
数据连接这一块:
Set MyDB = Workspaces(0).OpenDatabase(Sys_Path & "\Data\hxicyb.MDB", False, False, ";pwd=2001")
Set MyRs = MyDB.OpenRecordset("user", dbOpenTable)

转换为sql server后如何做,以及将来升级网络版都要做哪些工作。

我想问一些数据库转换的问题,还有我的系统原来的报表打印是这样写的
Dim xlapp As excel.Application
Set xlapp = New excel.Application
xlapp.Visible = False
xlapp.SheetsInNewWorkbook = 1
Set xlbook = xlapp.Workbooks.Open(Sys_Path & "\daypaper.xls")
With xlapp.ActiveSheet
.Cells(3, 6).Value = Date '用户编码


请问用SQL SERVER以后能否不用上述方法直接用程序写
请赐教!
回复
huoleifeng 2002-05-05
dim adocon as adodb.connection
dim adorst as adodb.recordset
set adocon =new adodb.connection
set adorst=new adodb.recordset
adocon.connectionstring="dsn=ODBC中连接数据库的名字;uid=sa;pwd="
adocon.open
adorst.cursorlocation=........
adorst.cursortype=........
adorst.locktype=.........
adorst.activeconnection= adocon
adorst.open "select * from 数据库中表的名字
回复
年糕 2002-05-05
打开数据库连接
Dim Conn As New ADODB.Connection
Conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=" & sa密码 & ";Initial Catalog=" & 数据库名称 & ";Data Source=" & 服务器名称
打开表:
Dim Rec As New ADODB.Recordset
Rec.CursorLocation = adUseClient
Rec.Open "SQL语句", Conn, adOpenDynamic, adLockOptimistic, adCmdText
回复
csscsh 2002-05-05
Dim Cnn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
'连接数据库
Cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=" & sa密码 & ";Initial Catalog=" & 数据库名称 & ";Data Source=" & 服务器名称
'打开指定的表,如:table1
Rs.CursorLocation = adUseClient
Rs.Open "select * from table1", Conn, adOpenDynamic, adLockOptimistic, adCmdText
回复
xdd1125 2002-05-05
用ADO,与连接ACCESS的mdb在形式上是一样的,只不过OLEDB提供者是sqloledb,data source(或者server)是sql server的server名称,另外加上uid和pwd就可以了

dim cn as new adodb.connect
dim rs as new adodb.recordset
dim constring as string
dim sql as string
constring="PROVIDER=sqloledb;server= servername ;UID=sa;PWD=;"
sql="select * from yourtable"
cn.open constring '打开连接
rs.open con,sql '打开表
回复
xdd1125 2002-05-05
用ADO,与连接ACCESS的mdb在形式上是一样的,只不过OLEDB提供者是sqloledb,data source(或者server)是sql server的server名称,另外加上uid和pwd就可以了

dim cn as new adodb.connect
dim rs as new adodb.recordset
dim constring as string
dim sql as string
constring="PROVIDER=sqloledb;server= servername ;UID=sa;PWD=;"
sql="select * from yourtable"
cn.open constring '打开连接
rs.open con,sql '打开表
回复
softrain 2002-05-05
dim con as new adodb.connect
dim record as new adodb.recordset
dim constring as string
dim sql as string
constring="PROVIDER=sqloledb;server= servername ;inital catalog=dbname ;UID=sa;PWD=;"
sql="select * from yourtable where yourtable.id<50"
con.open constring '打开连接
record.open con,sql '打开表


回复
lovingkiss 2002-05-05
打开数据库连接
Dim Conn As New ADODB.Connection
Conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=" & sa密码 & ";Initial Catalog=" & 数据库名称 & ";Data Source=" & 服务器名称
打开表:
Dim Rec As New ADODB.Recordset
Rec.CursorLocation = adUseClient
Rec.Open "SQL语句", Conn, adOpenDynamic, adLockOptimistic, adCmdText
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告