展开全部
工程->引用->Microsoft ActiveX Data Objects 2.0 Library (后面为版本号)
Dim rs As New ADODB.Recordset, cn As New ADODB.Connection
'向数据库中添加数据
Private Sub Command2_Click()
If rs.State = adStateOpen Then rs.Close
rs.Open "SELECT * FROM USERPASSWORD", cn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!UID = txtUid.Text
rs!PWD = txtPwd.Text
rs!TRUENAME = txtName.Text
rs!CREATEDATE = Format(Now, "YYYY/MM/DD")
rs.Update
Command1.Value = True
End Sub
Private Sub Form_Load()
'连接 SQL SERVER 数据库
cn.ConnectionString = "Driver={SQL Server};SERVER=DataServer;DATABASE=zxzx;UID=information;PWD=information*"
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
--------------------------------------------------------------------
Private Sub Form_Load()
Dim strConn As String
Dim pubConn As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim strSQL As String
strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=develop; password=12345;Data Source=ServerName"
pubConn.Open strConn
rsTable.CursorLocation = adUseClient
strSQL = "select * from TableName"
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsTable
End Sub
--------------------------------------------------------------------
dim cnn as new ADODB.Connection
dim rs as Adodb.recordset
dim s as string,i as long
cnn.CursorLocation = 3 '
cnn.CommandTimeout = 30
cnn.Open "Provider=SQLOLEDB;Data Source=192.168.0.11;User ID=sa;Password=sa;Initial Catalog=tempdb;Persist Security Info=True"
set rs = nothing
set rs = cnn.execute("select * from sysobjects")
while not rs.eof
for i = 0 to rs.fields.count - 1
s = s & rs(i) & vbtab
next
s = s & vbcrlf
rs.movenext
wend
msgbox s
Dim rs As New ADODB.Recordset, cn As New ADODB.Connection
'向数据库中添加数据
Private Sub Command2_Click()
If rs.State = adStateOpen Then rs.Close
rs.Open "SELECT * FROM USERPASSWORD", cn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!UID = txtUid.Text
rs!PWD = txtPwd.Text
rs!TRUENAME = txtName.Text
rs!CREATEDATE = Format(Now, "YYYY/MM/DD")
rs.Update
Command1.Value = True
End Sub
Private Sub Form_Load()
'连接 SQL SERVER 数据库
cn.ConnectionString = "Driver={SQL Server};SERVER=DataServer;DATABASE=zxzx;UID=information;PWD=information*"
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
--------------------------------------------------------------------
Private Sub Form_Load()
Dim strConn As String
Dim pubConn As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim strSQL As String
strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=develop; password=12345;Data Source=ServerName"
pubConn.Open strConn
rsTable.CursorLocation = adUseClient
strSQL = "select * from TableName"
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsTable
End Sub
--------------------------------------------------------------------
dim cnn as new ADODB.Connection
dim rs as Adodb.recordset
dim s as string,i as long
cnn.CursorLocation = 3 '
cnn.CommandTimeout = 30
cnn.Open "Provider=SQLOLEDB;Data Source=192.168.0.11;User ID=sa;Password=sa;Initial Catalog=tempdb;Persist Security Info=True"
set rs = nothing
set rs = cnn.execute("select * from sysobjects")
while not rs.eof
for i = 0 to rs.fields.count - 1
s = s & rs(i) & vbtab
next
s = s & vbcrlf
rs.movenext
wend
msgbox s
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询