VB6.0数据库学习笔记
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim comm As New ADODB.Command
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
MsgBox Me.DataGrid1.Columns("username").CellValue(Me.DataGrid1.Bookmark) ’改变列时的事件
End Sub
Private Sub Form_Load()
conn.CursorLocation = adUseClient '注意,一定要的
conn.Open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=stock;Data Source=20081120-2113\SQLEXPRESS" ‘2005
Set comm.ActiveConnection = conn
comm.CommandText = "SelectUsersDynamic" '执行带参数的存储过程
comm.CommandType = adCmdStoredProc
Dim pm As ADODB.Parameter
Set pm = New ADODB.Parameter
Set pm = comm.CreateParameter("@WhereCondition", adVarChar, adParamInput, 150, "issupplier=0")
comm.Parameters.Append pm
Set pm = comm.CreateParameter("@OrderByExpression", adVarChar, adParamInput, 150, "users.userid")
comm.Parameters.Append pm
Set rs = comm.Execute()
'rs.CursorType = adOpenKeyset
'rs.LockType = adLockOptimistic
'rs.Open "select userid,username from users", conn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = rs
Set rs = Nothing
Set conn = Nothing
End Sub
Dim rs As New ADODB.Recordset
Dim comm As New ADODB.Command
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
MsgBox Me.DataGrid1.Columns("username").CellValue(Me.DataGrid1.Bookmark) ’改变列时的事件
End Sub
Private Sub Form_Load()
conn.CursorLocation = adUseClient '注意,一定要的
conn.Open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=stock;Data Source=20081120-2113\SQLEXPRESS" ‘2005
Set comm.ActiveConnection = conn
comm.CommandText = "SelectUsersDynamic" '执行带参数的存储过程
comm.CommandType = adCmdStoredProc
Dim pm As ADODB.Parameter
Set pm = New ADODB.Parameter
Set pm = comm.CreateParameter("@WhereCondition", adVarChar, adParamInput, 150, "issupplier=0")
comm.Parameters.Append pm
Set pm = comm.CreateParameter("@OrderByExpression", adVarChar, adParamInput, 150, "users.userid")
comm.Parameters.Append pm
Set rs = comm.Execute()
'rs.CursorType = adOpenKeyset
'rs.LockType = adLockOptimistic
'rs.Open "select userid,username from users", conn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = rs
Set rs = Nothing
Set conn = Nothing
End Sub