用LotusScript连接MSSQL2000实例(ADO)
广告投放★自助友情CMS落伍广告联盟晒乐广告联盟脉动广告联盟品味广告联盟
广告位可自定样式联系QQ:38355018个文字广告月20元广告联系QQ:3835501广告位可自定样式
8个文字广告月20元黄金广告位每月20元广告位可自定样式联系QQ:3835501广告位可自定样式
左旋肉碱、全国包邮
买二送一、无效退款

文章浏览→编程相关Mssql→用LotusScript连接MSSQL2000实例(ADO)

用LotusScript连接MSSQL2000实例(ADO)
用LotusScript连接MSSQL2000实例(ADO)

用ADO连接SQL是比较好的,不用象ODBC一样建DSN,速度快,稳定。这一段代码,作用是从ERP系统中抓取零件的主信息,更新到Lotus中。

Sub Initialize
 On Error Goto err_code
 starttime=Now
 Dim session As New Notessession
 Dim db As Notesdatabase
 Dim doc As notesdocument
 Dim view As NotesView
 Dim c As NotesViewEntryCollection
 
 
 Set db=session.currentdatabase
 Set view=db.GetView("All Parts Doc")
 Set c=view.AllEntries
 If c.Count<>0 Then
  T=c.Count
  Call c.RemoveAll(False)
  Print "Update SC01- ADO:Old records "+Cstr(T)+"removed"
 End If
 
 Dim pdoc As NotesDocument
 Set pdoc=db.GetProfileDocument("Profile")
 Set doc=New notesdocument(db)
 doc.form = "Supplier"
 Print "Update SC01- ADO:Initializecompleted"
 
 Dim conn As Variant
 Set conn = CreateObject("ADODB.Connection")
 ConnAdmin = "driver={SQLServer};server=ServerIP;database=DBName;uid=xxx;pwd=xxx"
 conn.open ConnAdmin
 Set rstt=createobject("adodb.recordset")
 SQL="SELECTSC01001,SC01002,SC01010,SC01042,SC01043,SC01044,SC01045,SC01053,SC01056,SC01058,SC01059,SC01066,SC01087,SC01097,SC01099from SC010100 where SC01066=6 or SC01066=7"
 rstt.open SQL,conn,1,3
 Print "Update SC01- ADO:Database connected"
 r=0
 Do While Not rstt.eof
  For i=0 To 14
  field=rstt.Fields(i).name
  value=rstt.Fields(i).value
   Set item =doc.AppendItemValue(field,value)
  Next
  rstt.MoveNext
  Call doc.save(True,True)
  Set db = session.CurrentDataBase
  Set doc = New NotesDocument(db)
  doc.form = "Supplier"
  R=R+1
 Loop
 rstt.close
 Print "Update SC01- ADO:Update completed"
 endtime=Now
 Set mail = New NotesDocument(db)
 mail.form="Memo"
 mail.principal="WUX Price Adjust 2"
 mail.Subject="ADO:Success Import "+Cstr(R)+"Records from SC01[start at "+Cstr(starttime)+"], Old records"+Cstr(T)+" Deleted. [end at"+Cstr(endtime)+"]"
 Call mail.send(True,pdoc.SystemMessage)
 
 Exit Sub
err_code:
 Dim erm As New NotesDocument(db)
 erm.form="Memo"
 erm.subject=db.title+": Error in 'Update SC01from scala ADO' agent . "+Str(Err)+" At "+Str(Erl)+"."+Error$
 txt="Server: "+db.server+Chr(10)+"File:"+db.FilePath
 If er<>"" Then
  txt=txt+"sending to"+er
 End If
 erm.body=txt
 Call erm.send(False,"yang li")
End Sub


 

所属分类:编程相关Mssql    作者:新浪博客    时间:2010-11-20 0:00:00

文章导航