GetGridViewByConditionForm.aspx:
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] != null)
{
SqlConnection conn=null;
SqlCommand cmd = null;
SqlDataAdapter アダプター = null;
試してください
{
conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
conn.Open();
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
String cmdStr = "select * from dbo.Customers";
if (Request["id"].ToString()!=String.Empty)
{
cmdStr = " where CustomerID= '" Request["id"].ToString() "'";
}
cmd.CommandText = cmdStr;
adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
this.gvData.DataSource = ds;
this.gvData.DataBind();
}
catch
{
Response.Write("エラーが発生しました!");
Response.Flush();
Response.End();
}
最後に
{
if (adapter != null)
{
adapter.Dispose();
}
if (cmd != null)
{
cmd.Dispose();
}
if ((conn != null) && (conn.State == ConnectionState.Open))
{
conn.Close();
}
}
}
}