コード例 #1
0
    protected void GridviewBind()
    {
        string OLMSDBConnectionString = ConfigurationManager.ConnectionStrings["OLMSDB"].ConnectionString;
        var    OLMSDBConnection       = new MySqlConnection(OLMSDBConnectionString);

        string       stackid       = Session["STACKID"].ToString();
        MySqlCommand get_sql       = new MySqlCommand("select ShelfId,Summary,Timestamp from Shelves where StackId='" + stackid + "';");
        var          resultAdapter = new MySqlDataAdapter();

        resultAdapter.SelectCommand            = get_sql;
        resultAdapter.SelectCommand.Connection = OLMSDBConnection;
        var resultSet = new DataSet();

        OLMSDBConnection.Open();
        resultAdapter.Fill(resultSet);
        OLMSDBConnection.Close();

        DataTable searchResult = resultSet.Tables[0];

        Shelves.DataSource   = searchResult;
        Shelves.DataKeyNames = new string[] { "ShelfId" };
        Shelves.DataBind();
        if (Shelves.HeaderRow != null)
        {
            Shelves.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    }