这例子很好,慢慢研究!
<%@Page Language="C#"%><%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %><%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Using Explicit Parameters with a Stored Procedure</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Using Explicit Parameters with a Stored Procedure</span><hr />
<!---------------------------------------------------------------------------><%-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server"/><div>Connection string: <b><span id="outConnect" runat="server"></span></b></div>
<div>Command Text: <b><span id="outCommandText" runat="server"></span></b></div>
<div>Input Parameter: <b><span id="outInParams" runat="server"></span></b></div>
<div>Output Parameters: <b><span id="outOutParams" runat="server"></span></b></div>
<div id="outError" runat="server">&nbsp;</div><script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e)
{ // get connection string from ..\global\connect-strings.ascx user control
string strConnect = ctlConnectStrings.OLEDBConnectionString;
outConnect.InnerText = strConnect; // and display it // specify the name of the stored procedure to use as the CommandText
string strCommandText = "FindFromISBN";
outCommandText.InnerText = strCommandText; // and display it // create a new Connection object using the connection string
OleDbConnection objConnect = new OleDbConnection(strConnect); // create a new Command object and set the CommandType
OleDbCommand objCommand = new OleDbCommand(strCommandText, objConnect);
objCommand.CommandType = CommandType.StoredProcedure; // create a variable to hold a Parameter object
OleDbParameter objParam; // create a new Parameter object named 'ISBN' with the correct data
// type to match a SQL database 'varchar' field of 12 characters
objParam = objCommand.Parameters.Add("ISBN", OleDbType.VarChar, 12); // specify that it// s an Input parameter and set the value
objParam.Direction = ParameterDirection.Input;
objParam.Value = "1861002882"; // create a new Parameter object named 'Title' with the correct data
// type to match a SQL database 'varchar' field of 50 characters
// and specify that it's an output parameter (so no value required)
objParam = objCommand.Parameters.Add("Title", OleDbType.VarChar, 50);
objParam.Direction = ParameterDirection.Output; // create another output Parameter object named 'Date' with the correct
// data type to match a SQL database 'datetime' field
objParam = objCommand.Parameters.Add("Date", OleDbType.DBDate);
objParam.Direction = ParameterDirection.Output; // display the value of the input parameter
outInParams.InnerText = "ISBN='" + objCommand.Parameters["ISBN"].Value + "'"; try
{
// open the connection and execute the command
objConnect.Open();
objCommand.ExecuteNonQuery();
objConnect.Close();    // then close the connection
}
catch (Exception objError)
{
// display error details
outError.InnerHtml = "<b>* Error while accessing data</b>.<br />"
+ objError.Message + "<br />" + objError.Source;
return;  //  and stop execution
} // collect the values of the output parameters - note the use of
// the ToString method as they will contain DBNull if there was no
// match for the ISBN and this will cause an error if displayed
string strTitle = objCommand.Parameters["Title"].Value.ToString();
string strDate = objCommand.Parameters["Date"].Value.ToString();
outOutParams.InnerHtml = "Title='" + strTitle + "' &nbsp; Date=" + strDate; }
</script><!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

解决方案 »

  1.   

    Dim myConn As SqlClient.SqlConnection
            Dim myCommand As SqlClient.SqlCommand
            Dim myReader As SqlClient.SqlDataReader
            Dim myOutput As ParameterDirection
            Dim Sql As String
            Dim ConnStr As String = Application("Connt_Login") '数据库连接串
            myConn = New SqlClient.SqlConnection(ConnStr)
            myConn.Open()
            myCommand = New SqlClient.SqlCommand("online", myConn)
            myCommand.CommandType = System.Data.CommandType.StoredProcedure
            myCommand.Parameters.Add("@S_Id", SqlDbType.Char).Value = "111" 
            myCommand.Parameters.Add("@P_Id", SqlDbType.Char).Value = "-100" 
            myCommand.Parameters.Add("@Lb", SqlDbType.Char).Value = "T" 
            myCommand.Parameters.Add("@CountUser", SqlDbType.Int).Value = 0        myReader = myCommand.ExecuteReader
      

  2.   

    asp.net 高级编程  又说到这个,但都不详细,而且没有电子版的!:(从这个例子应该大概能看出用法了吧?
      

  3.   

    to  milchcow:
      myCommand = New SqlClient.SqlCommand("online", myConn)
    这个online是不是sql server中的存储过程?
      

  4.   

    online就是sqlserver中的存储过程!