<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<H4>Using Parameters</H4>
<script language="VB" runat="server">
  Sub Page_Load(Source As Object, E As EventArgs) 
    
    Dim myConnection As OleDbConnection
    Dim dr          As  OleDbDataReader
    Dim ConnStr      As String
    '设置连接
    ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=Pubs; User ID=sa"
    myConnection = New OleDbConnection(ConnStr)
    
    '设置DataCommand
    Dim myCommand As New OleDbCommand("p_authors", myconnection)
    myCommand.CommandType = CommandType.StoredProcedure
   
   '设置参数集
    Dim objParam As OleDbParameter
    objParam = myCommand.Parameters.Add("State", OleDbType.VarChar, 10)
    objParam.Direction = ParameterDirection.Input
    objParam.Value = "CA"
    Try
          '打开连接并执行
           myconnection.Open()
           '执行ExecuteReader 方法返回一个 DataReader
 	   dr = myCommand.ExecuteReader()   
        Catch objError As Exception
        '出现错误停止执行并显示出错信息
         Exit Sub  ' 
     
     End Try
     DataGrid1.DataSource=dr
    DataGrid1.DataBind()
  End Sub
</script>
</head>
<body>
<form  runat=server>
	 <asp:DataGrid id="DataGrid1" runat="server" /> 
</form>
</body>
</html>
