手把手教你使用VB来创建ASP组件(4)
程序员文章站
2022-03-26 09:26:19
3、 add方法
add方法的目的是向中添加一条新的cd信息,因此它打开的记录集要求能够更新。这就不能像opendb中那样仅用open打开数据集。详细的代码见下面:
private sub...
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
上一篇: 深入理解Java NIO
下一篇: 长安居大不易--用大数据分析西安租房现状