T-SQL代码:-->创建存储过程 GetEmployeeInfo go create proc GetEmployeeInfo (--定义参数和参数的默认值 @employee varchar(10)='lovers' ) as select em.id,em.employee,dm.department from Employee em inner join Department dm on em.department=dm.id where em.employee=@employee exec GetEmployeeInfo .cs 文件 调用存储过程GetEmployeeInfo using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; public partial class StoredProcedure : System.Web.UI.Page { string strCon = ConfigurationManager.ConnectionStrings[1].ToString(); private void Connect(string name) { SqlConnection sqlCon = new SqlConnection(strCon); SqlCommand sqlCmd = new SqlCommand("GetEmployeeInfo", sqlCon); sqlCmd.Parameters.AddWithValue("@employee",name); sqlCmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter adapter = new SqlDataAdapter(sqlCmd); DataSet ds = new DataSet(); adapter.Fill(ds); foreach (DataRow dr in ds.Tables[0].Rows) Response.Write(dr["Employee"].ToString()+"<br/>"+dr["Department"].ToString()); } protected void Page_Load(object sender, EventArgs e) { Connect("lovers"); } }