(1)好象无法实现
(3)通过传递adasyncconnect值给open方法的options参数
当异步打开连接时必须决定何时准备连接,有两种方法:定时询问connection的state属性或使用事件。
1.定时询问state属性是最简单的办法,但是当企图连接时如果需要完成复杂操作,则不适合
dim cn as new adodb,connection
on error resume next
cn.open "provider=sqloledb;data souce=myserver;initial catalog=pubs;" & "user id=sa;password= ;",,,adasyncconnect
do while=(cn.state and adstateconnecting)
'你要进行的操作'
.....
doevents
loop
if cn.state and asstateopen then msgbox "the connection is open"
2.更好的方法是用connectcomplete事件,用withevent关键字说明connection对象变量
dim withevents cn as adodb.connection
private sub cmdconnect_click()
set cn=new adodb.connection
cn.connectiontimeout=20
cn.open "provider=sqloledb;data source=myserver;" & "lnitial catalog=pubs;",
"sa",,adasyncconnect
end sub
private aub cn_connectcomplete(byval perror as adodb.error,adstatus as
adodb.eventstatusenum,byval pconnection as adodb.connection)
if adstatus=adstatusok then
msgbox "the connection is open"
elseif adstatus=adstatuserrorsoccurred then
msgbox "unable to open the connection" & vbcr & err.description
end if
end sub
(3)通过传递adasyncconnect值给open方法的options参数
当异步打开连接时必须决定何时准备连接,有两种方法:定时询问connection的state属性或使用事件。
1.定时询问state属性是最简单的办法,但是当企图连接时如果需要完成复杂操作,则不适合
dim cn as new adodb,connection
on error resume next
cn.open "provider=sqloledb;data souce=myserver;initial catalog=pubs;" & "user id=sa;password= ;",,,adasyncconnect
do while=(cn.state and adstateconnecting)
'你要进行的操作'
.....
doevents
loop
if cn.state and asstateopen then msgbox "the connection is open"
2.更好的方法是用connectcomplete事件,用withevent关键字说明connection对象变量
dim withevents cn as adodb.connection
private sub cmdconnect_click()
set cn=new adodb.connection
cn.connectiontimeout=20
cn.open "provider=sqloledb;data source=myserver;" & "lnitial catalog=pubs;",
"sa",,adasyncconnect
end sub
private aub cn_connectcomplete(byval perror as adodb.error,adstatus as
adodb.eventstatusenum,byval pconnection as adodb.connection)
if adstatus=adstatusok then
msgbox "the connection is open"
elseif adstatus=adstatuserrorsoccurred then
msgbox "unable to open the connection" & vbcr & err.description
end if
end sub
或connection对象的动态属性。jet oledb:system database是工作组上的信息文
件的路径和名字,oledb:registry path是为jet引擎保留的registry关键字,jet
oledb:database password是数据库口令:
cn.properties("jet oledb:database password")="mypwd"
Set DBase = OpenDatabase("database.mdb", False, False, "ms access;pwd=XX")
注意是XX而不是'XX',False也绝不能省略
(3)已解决,多谢了,20分奉上 ,现又出现 记录集 事件无法响应,详细情况请看我另一个帖子“ADO 的记录集 如何建立 事件?”(50分),还望能指点一下(4),你说的我不大理解,等我再看看,过后给分
系统不允许部分给分,过几天一定补上
第4个问题,我一般在sub main中设定Odbc的连接字串,没使用过dsn.如下:
dim cn as new Adodb.Connetction
cn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & app.path & "\test.mdb;Uid=DataBaseUserName;Pwd=YourPassword;"if cn.state<>adStateOpen then
msgbox "连接资料库错误!"
.............
end if
其余的你可參考決定或改作通用的activeX控件. (1)新建一ActiveX Control工程.
放置一maskedit控件於上.
其設置屬性參考如下:
usercontrol之name:DataDate.
usercontrol之DataBindingBehavior設定1-VvbSimpleBound
MaskedtBox之name:mskDate. (2).新增一數據屬性用於綁定.操作如下(我用為繁體系統,可能說法不大一樣).
打開菜單: 增益集-->增益集管理員.
載入Visual Basic AcitveX控制項介面精靈並啟動.
運行至:建立自訂的介面成員處新增一Property:DateValue(此屬性即為您要操作綁定的東東).
下一步確定對應關系:
將常用的公用項目中的屬性事件按照綁定至mskDate.如mskDate無相關之屬性和可綁定至usercontrol上.
在公用項目中將DateValue之資料類型設定Date型
完成上述操作.
(3). 將DateValue設定資料綁定屬性. 點選usercontrol。
打開 工具--->程序屬性.
從名稱欄位選擇DateValue.
將資料連結項中如下選擇打上勾:
“屬性具資料連結功能”
“在屬性值改變前,先呼叫CanPropertyChange.
“即時更新” 此時DataValue即具有數據綁定功能。此控件的屬性中就會增加諸如DataSource.DataField等東東. (4).編寫代碼。
a.設定控件大小. Private Sub UserControl_Resize()
MskDate.Move 0, 0, UserControl.Width, usercontrol.Height
End Sub
b.將dateValue的代碼修正如下:
Public Property Let DateValue(ByVal New_DateValue As Date)
m_DateValue = New_DateValue
PropertyChanged "DateValue"
If Not IsEmpty(m_DateValue) Then
If IsDate(m_DateValue) Then
If Year(m_DateValue) > 1970 Then
MskDate.Text = Format(m_DateValue, "yyyy/mm/dd")
Else
MskDate.Text = "____/__/__"
End If
Else
MskDate.Text = "____/__/__"
End If
Else
MskDate.Text = "____/__/__"
End If
End Property
,此處即為判斷所傳進來的值是否合乎要求,如果是有效的話就顯示在mskDate中,否則就顯示成其他的方式。Private Sub MskDate_Validate(Cancel As Boolean)If IsDate(Trim(MskDate.Text)) Then
If CanPropertyChange("DateValue") Then
m_DateValue = CDate(MskDate.Text)
PropertyChanged "DateValue"
End If
Else
MsgBox "Invalid date value!", vbExclamation, "Date Error!"
If Not IsEmpty(m_DateValue) Then
If IsDate(m_DateValue) Then
If Year(m_DateValue) > 1970 Then
MskDate.Text = Format(m_DateValue, "yyyy/mm/dd")
Else
MskDate.Text = "____/__/__"
End If
Else
MskDate.Text = "____/__/__"
End If
Else
MskDate.Text = "____/__/__"
End If
End If
End Sub'此處即判斷mskDate的值是否有效,如果有效的話就調用 PropertyChanged "DateValue" . 資料就會更改DataField所綁定的資料欄位的值 .
最後將工程編譯成控件DataDate.ocx 加以引用,DataValue屬性即相當於text的text屬性在文檔中可以直接調用.
用以上方法可以自定義資料綁定控件用於我們的特殊處理。 lee_jvn於2001.02.15
OICQ:37198873
多谢您的帮助
不过我看你好象没有用到maskedbox的mask属性,大致看过你的代码,我觉得这样做的话,不见得要用maskedbox,用textbox就可以了你能讲述一下你的思路么?
-----一家之言,仅供参考---------