Exemplo n.º 1
0
    /// <summary>
    /// Bind table data to DataGridView
    /// </summary>
    public void ShowTableData()
    {
        try
        {
            this.curTable.Text = "";
            SqlServer server = SqlServer.CurrentServer;
            server.Connect();

            SqlDatabase database = SqlDatabase.CurrentDatabase(server);

            SqlTable table = database.Tables[HttpContext.Current.Server.HtmlDecode(HttpContext.Current.Request["table"])];
            if (table.PrimaryKeys == null || table.PrimaryKeys.Length < 1)
            {
                table.AddIDColumn();
            }
            if (table == null)
            {
                server.Disconnect();

                // Table doesn't exist - break out and go to error page
                Response.Redirect(String.Format("error.aspx?error={0}", 1002));
                return;
            }

            this.GridView_ViewTableData.DataSource = table.GetTableData();
            this.GridView_ViewTableData.DataBind();


            this.curTable.Text = "Table - " + table.Name;

            server.Disconnect();
        }
        catch (Exception ex)
        {
            this.MessageLabel.Text = ex.ToString();
        }
    }