你的问题在哪里?
对于存储过程,只需创建:
CREATE PROCEDURE dbo.ReadEmployees @EmpID INT
AS
SELECT * -- I would *strongly* recommend specifying the columns EXPLICITLY
FROM dbo.Emp
WHERE ID = @EmpID
这就是全部。
在您的ASP.NET应用程序中,只需创建一个sqlConnection
和一个sqlCommand
(不要忘记设置CommandType = CommandType.StoredProcedure
)
DataTable tblEmployees = new DataTable();
using(sqlConnection _con = new sqlConnection("your-connection-string-here"))
using(sqlCommand _cmd = new sqlCommand("ReadEmployees", _con))
{
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add(new sqlParameter("@EmpID", sqlDbType.Int));
_cmd.Parameters["@EmpID"].Value = 42;
sqlDataAdapter _dap = new sqlDataAdapter(_cmd);
_dap.Fill(tblEmployees);
}
YourGridView.DataSource = tblEmployees;
YourGridView.DataBind();
然后DataTable
用该数据填充例如a并将其绑定到例如GridView。