vb12sql吧 关注:65贴子:371
  • 6回复贴,共1

vb-sqlserver增删改查

只看楼主收藏回复

【配置】:用户名,密码,IP 端口,数据库名称
1:将配置文件放入 DataBase.ini 文档[uid]=sa[pwd]=dwz10110511[srn]=127.0.0.1,1754[sysdb]=yygl
2:建立标准模块 Module1
Public SRN As String
Public uID As String
Public PWD As String
Public SysDB As String
'系统的 main() 主函数 读取配置文件
Sub Main()
Dim Intext As String Open (App.Path & "\DataBase.ini") For Input As #1
Line Input #1, Intext
uID = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Line Input #1, Intext
PWD = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Line Input #1, Intext
SRN = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Line Input #1, Intext
SysDB = Mid(Intext, 9, Len(Trim(Intext)) - 8)
Close #1
登录窗口.Show vbModal
End Sub
【select】:
Dim conn As New ADODB.Connection'建立连接对象
Dim rs As New ADODB.Recordset'记录集对象
conn.Open "provider=SQLOLEDB;Data Source=" & SRN & ";User ID=" & uID & ";Password=" & PWD & ";Initial catalog=" & SysDB
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.Open "select * from 病区管理", conn, , , adCmdText
Set msf1.DataSource = rs
msf1.Refresh
'关闭连接 释放内存
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
【insert,delete,update】:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.Open "provider=SQLOLEDB;Data Source=" & SRN & ";User ID=" & uID & ";Password=" & PWD & ";Initial catalog=" & SysDB
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
conn.Execute "insert,delete,update的语句"
'关闭连接 释放内存
conn.Close
Set rs = Nothing
Set conn = Nothing


1楼2013-06-28 20:31回复
    [uid]=sa
    [pwd]=dwz10110511
    [srn]=127.0.0.1,1754
    [sysdb]=yygl


    2楼2013-06-28 20:31
    回复
      [uid]=sa ' 用户名
      [pwd]=dwz10110511 '密码
      [srn]=127.0.0.1,1754'IP 端口
      [sysdb]=yygl'该IP的服务器sqlserver的的数据库的名称


      3楼2013-06-29 21:31
      回复
        默默地顶


        4楼2013-08-07 17:40
        收起回复
          学习一下


          IP属地:河北5楼2016-09-01 16:41
          回复


            IP属地:广东来自Android客户端6楼2016-09-06 05:59
            回复