Allocateclassbasics
Allocateclassbasics
Here's an updated code snippet that assumes the DataGridView already exists:
```
// Create a query
SELECT
studentId,
StudentSurname,
StudentName
FROM
stdstudentdetails
";
// Create a DataTable
connection.Open();
dataTable.Load(reader);
columnClassAllocationDate.Name = "ClassAllocationDate";
dataGridView1.Columns.Add(columnClassAllocationDate);
columnClassAllocated.Name = "ClassAllocated";
string[] studentClasses = { "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6" };
columnClassAllocated.Items.AddRange(studentClasses);
dataGridView1.Columns.Add(columnClassAllocated);
columnImage.HeaderText = "Image";
columnImage.Name = "Image";
dataGridView1.Columns.Add(columnImage);
columnButton.Name = "UploadImage";
columnButton.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(columnButton);
columnActivate.HeaderText = "Activate";
columnActivate.Name = "Activate";
columnActivate.Text = "Activate";
columnActivate.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(columnActivate);
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
dataGridView1.DataSource = dataTable;
if (e.ColumnIndex == dataGridView1.Columns["UploadImage"].Index)
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = openFileDialog.FileName;
dataGridView1.Rows[e.RowIndex].Cells["Image"].Value = filePath;
string classAllocationDate =
dataGridView1.Rows[e.RowIndex].Cells["ClassAllocationDate"].Value.ToString();
string classAllocated =
dataGridView1.Rows[e.RowIndex].Cells["ClassAllocated"].Value.ToString();
// Create a query
";
// Create a SqlCommand
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
command.Parameters.AddWithValue("@studentId", studentId);
command.Parameters.AddWithValue("@classAllocationDate", classAllocationDate);
command.Parameters.AddWithValue("@classAllocated", classAllocated);
command.Parameters.AddWithValue("@image", image);
command.ExecuteNonQuery();
```