VB调用存储过程


存储过程:

Create Proc sp_insert
@F_Code varchar(10),@F_Name varchar(100),@F_Address varchar(100),@F_tel int,@F_BuildDate smalldatetime,@F_TotalPersons int
as
insert into Fa_Family(Fa_Code,Fa_Name,Fa_Address,Fa_Tel,Fa_BuildDate,Fa_TotalPersons)Values
(@F_Code,@F_Name,@F_Address,@F_Tel,@F_BuildDate,@F_TotalPersons)
return

代码:

Private Sub Command2_Click()
  Dim conn As ADODB.Connection  '定义
  Dim rs As ADODB.Recordset
  Dim AdoCom As ADODB.Command
  
  Set conn = New ADODB.Connection
  Set rs = New ADODB.Recordset
  Set AdoCom = New ADODB.Command
 
  conn.Provider = "SQLOLEDB"
  conn.ConnectionString = "Driver={sql server};server=ALEX;uid=sa;pwd=;database=family"
  conn.Open  '打开连接
 
  Set AdoCom.ActiveConnection = conn

  AdoCom.CommandText = "sp_insert"
  AdoCom.CommandType = adCmdStoredProc

  AdoCom.Parameters("@F_Code") = Text1.Text
  AdoCom.Parameters("@F_Name") = Text2.Text
  AdoCom.Parameters("@F_Address") = Text3.Text
  AdoCom.Parameters("@F_Tel") = Text4.Text
  AdoCom.Parameters("@F_BuildDate") = Text5.Text
  AdoCom.Parameters("@F_TotalPersons") = Text6.Text

  Set rs = AdoCom.Execute
End Sub

posted @ 2007-07-13 16:35  杰仔  阅读(500)  评论(0编辑  收藏  举报