コード例 #1
0
        //PopolateGridView

        void PopolateGridView()
        {
            DataTable dataTable = new DataTable();

            using (SqlConnection cnn = new SqlConnection(sqlconnectionString))
            {
                cnn.Open();
                SqlDataAdapter adapter = new SqlDataAdapter("select * from Raum", cnn);

                adapter.Fill(dataTable);
            }
            if (dataTable.Rows.Count > 0)
            {
                Raum.DataSource = dataTable;
                Raum.DataBind();
            }
            else
            {
                dataTable.Rows.Add(dataTable.NewRow());
                Raum.DataSource = dataTable;
                Raum.DataBind();
                Raum.Rows[0].Cells.Clear();
                Raum.Rows[0].Cells.Add(new TableCell());
                Raum.Rows[0].Cells[0].ColumnSpan      = dataTable.Columns.Count;
                Raum.Rows[0].Cells[0].Text            = "Not Data Found ..!";
                Raum.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            }
        }