日期:2014-05-17 浏览次数:20606 次
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
SqlDataReader MyReader;
SqlParameter CityName;
SqlParameter number;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DSN_NorthWind"].ConnectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select top @number * from Customers where city=@city";
number = new SqlParameter();
number.ParameterName = "@number";
number.SqlDbType = SqlDbType.Int;
number.Value = 1;
CityName = new SqlParameter();
CityName.ParameterName = "@city";
CityName.SqlDbType = SqlDbType.VarChar;
CityName.Value = "Berlin";
cmd.Parameters.Add(CityName);
cmd.Parameters.Add(number);
conn.Open();
MyReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = MyReader;
GridView1.DataBind();
cmd.Dispose();
conn.Dispose();
}
}