存儲過程:CustomersPro
CREATE PROCEDURE CustomersPro
AS
select CustomerID,Address,City from Customers
GO
頁面代碼:
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e)
{
string conn="server=.;database=Northwind;uid=sa;pwd=sa";
SqlConnection myconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection=myconn;
cmd.CommandText = "CustomersPro";
cmd.CommandType= CommandType.StoredProcedure;
DataSet ds= new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds, "Customers");
GridView1.DataSource = ds.Tables["Customers"];
GridView1.DataBind();
}