I have a project which is nearly finished. I have a datagrid with a column for the project name and the rest of the columns are for the days of the month. My goal is to be able to display and let the user be able to change the hours worked for that day. Entered values will be saved to a database. I am having a hard time figuring out how to. Here is what I have for the code:
private void FillDays()
{
DaysView1.Columns.Clear();
DaysView1.DataSource = null;
var daysCount = DateTime.DaysInMonth(cyear, cmonth);
DataRow DayColumn;
string strSQLConnection = ConfigurationManager.ConnectionStrings["LocalDB"].ConnectionString;
string strselect = "SELECT Projects.ProjectName, Activity.Day, Activity.HoursDone FROM Projects left join ";
strselect += "(ProjectHours left join Activity on ProjectHours.ProjectHoursID = Activity.ProjectHoursID) ";
strselect += "on ProjectHours.ProjectID = Projects.ProjectID ";
strselect += " WHERE ProjectHours.Month = " + cmonth + " and ProjectHours.Year = " + cyear;
SqlDataAdapter myAdapter = new SqlDataAdapter(strselect, strSQLConnection);
SqlCommandBuilder myBuilder = new SqlCommandBuilder(myAdapter);
DataTable myTable = new DataTable();
myAdapter.Fill(myTable);
for (int i = 1; i <= daysCount; i++)
{
myTable.Columns.Add(i.ToString());
}
DaysView1.DataSource = myTable;
/*for (int i = 1; i <= daysCount; i++)
{
DaysView1.Columns.Add(new DataGridViewColumn() { HeaderText = i.ToString(), CellTemplate = new DataGridViewTextBoxCell() });
}*/
//DaysView1.Columns[1].Visible = false;
}

New Topic/Question
Reply




MultiQuote





|