手把手教你使用VB来创建ASP组件(4)
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.ConnectionDim NewRecordsetCD As New ADODB.RecordsetNewConn.Open "Provider=SQLOLEDB;DataSource=MUSE;Initial Catalog=Music;UserId=Wayne;Password=AbCdEfG"NewRecordsetCD.Open "SELECT * FROM CD", NewConn, adOpenDynamic, adLockOptimisticNewRecordsetCD.AddNewNewRecordsetCD.Fields("CD_ID") = IdNewRecordsetCD.Fields("CD_Name") = NameNewRecordsetCD.Fields("CD_Author") = AuthorNewRecordsetCD.Fields("CD_Price") = PriceNewRecordsetCD.Fields("CD_Information") = InformationNewRecordsetCD.UpdateEnd Sub解释:使用 NewRecordsetCD.AddNew,NewRecordsetCD.Fields(“Some_Key”)=Some_ValueNewRecordsetCD.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
相关文章:
热门推荐
- CSS2中鼠标激活显示背景色
- 1.网页制作JS代码优化经验总结
- 2.PHP100教程之深入理解PHP内核类的结构
- 3.教你如何用Eclipse创建一个Maven项目
- 4.用ports安裝apache13_modssl+mysql+php+phpmyadmin
- 5.IE6-8中Date不支持toISOString的修复方法是什么?修复方法分享
- 6.用JS来制作闪烁的边框
- 7.HTML5 的 Canvas 对象将改变 JavaScript 的使命
- 8.小白必看toString(),String.valueOf,(String)强转
- 9.C#获取系统当前IE版本号
- 10.PHP开发大型PHP项目的方法(二)