手把手教你使用VB来创建ASP组件(4)
2001-04-16 09:55:03 来源:WEB开发网核心提示:3、 Add方法Add方法的目的是向数据库中添加一条新的CD信息,因此它打开的记录集要求能够更新,手把手教你使用VB来创建ASP组件(4),这就不能像OpenDB中那样仅用Open打开数据集,详细的代码见下面:PRivate Sub Add(Id As String, Name As String, Author As
3、 Add方法
Add方法的目的是向数据库中添加一条新的CD信息,因此它打开的记录集要求能够更新。这就不能像OpenDB中那样仅用Open打开数据集。详细的代码见下面:
PRivate Sub Add(Id As String, Name As String, Author As String, Price As Currency, Information As String)
Dim NewConn As New ADODB.Connection
Dim NewRecordsetCD As New ADODB.Recordset
NewConn.Open "Provider=SQLOLEDB;DataSource=MUSE;Initial Catalog=Music;UserId=Wayne;PassWord=AbCdEfG"
NewRecordsetCD.Open "SELECT * FROM CD", NewConn, adOpenDynamic, adLockOptimistic
NewRecordsetCD.AddNew
NewRecordsetCD.Fields("CD_ID") = Id
NewRecordsetCD.Fields("CD_Name") = Name
NewRecordsetCD.Fields("CD_Author") = Author
NewRecordsetCD.Fields("CD_Price") = Price
NewRecordsetCD.Fields("CD_Information") = Information
NewRecordsetCD.Update
End Sub
解释:使用 NewRecordsetCD.AddNew,
NewRecordsetCD.Fields(“Some_Key”)=Some_Value
NewRecordsetCD.Update 来添加一条纪录
4、 Delete方法:
这个方法的目的是为了删除库中的某条CD名和相关的信息。它的实现方法是通过查询表中唯一的CD_ID来定位CD信息,从而删除该行纪录
Private Sub Delete(Id As String)
Dim NewConn As New ADODB.Connection
Dim RecordsetDelete As New ADODB.Recordset
NewConn.Open "Provider=SQLOLEDB;DataSource=MUSE;Initial Catalog=Music;UserId=Wayne;Password=AbCdEfG"
’从表中删除一条信息
NewConn.Execute "DELETE FROM CD WHERE CD_ID ='" & Id & "'", adCmdText + adExecuteNoRecords
End Sub
Add方法的目的是向数据库中添加一条新的CD信息,因此它打开的记录集要求能够更新。这就不能像OpenDB中那样仅用Open打开数据集。详细的代码见下面:
PRivate Sub Add(Id As String, Name As String, Author As String, Price As Currency, Information As String)
Dim NewConn As New ADODB.Connection
Dim NewRecordsetCD As New ADODB.Recordset
NewConn.Open "Provider=SQLOLEDB;DataSource=MUSE;Initial Catalog=Music;UserId=Wayne;PassWord=AbCdEfG"
NewRecordsetCD.Open "SELECT * FROM CD", NewConn, adOpenDynamic, adLockOptimistic
NewRecordsetCD.AddNew
NewRecordsetCD.Fields("CD_ID") = Id
NewRecordsetCD.Fields("CD_Name") = Name
NewRecordsetCD.Fields("CD_Author") = Author
NewRecordsetCD.Fields("CD_Price") = Price
NewRecordsetCD.Fields("CD_Information") = Information
NewRecordsetCD.Update
End Sub
解释:使用 NewRecordsetCD.AddNew,
NewRecordsetCD.Fields(“Some_Key”)=Some_Value
NewRecordsetCD.Update 来添加一条纪录
4、 Delete方法:
这个方法的目的是为了删除库中的某条CD名和相关的信息。它的实现方法是通过查询表中唯一的CD_ID来定位CD信息,从而删除该行纪录
Private Sub Delete(Id As String)
Dim NewConn As New ADODB.Connection
Dim RecordsetDelete As New ADODB.Recordset
NewConn.Open "Provider=SQLOLEDB;DataSource=MUSE;Initial Catalog=Music;UserId=Wayne;Password=AbCdEfG"
’从表中删除一条信息
NewConn.Execute "DELETE FROM CD WHERE CD_ID ='" & Id & "'", adCmdText + adExecuteNoRecords
End Sub
[]
- ››使用脚本恢复WinXP系统的用户登录密码
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››使用纯文本文件打造WCF服务
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
- ››使用 ADDRESS 与 INDIRECT函数查询信息
- ››使用 COLUMN函数编制单元信息
更多精彩
赞助商链接