I am developing a small project as an hobby and came to a dead end. I am using Visual Studio and SQL Server Management Studio.
I use Entity Framework model to be able to add data entries to a table with 4 columns. Two of those are supposed to log data entry taking place in 2017 like this:
if (CheckBoxBulb.Checked == true)
{
string roomNo = "";
roomNo = DropDownList1.SelectedValue.ToString();
testtable2017 entry = new testtable2017();
SqlConnection dataConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["iPadLoanConnectionString2"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE testtable2017 SET Last_Bulb_Replaced_2017 = '" + Calendar1.SelectedDate.ToString() + "' WHERE Room_No ='" + roomNo + "'";
cmd.Connection = dataConnection;
dataConnection.Open();
cmd.ExecuteNonQuery();
dataConnection.Close();
iPadEntities db = new iPadEntities();
db.testtable2017.Add(entry);
db.SaveChanges();
}
else if(CheckBoxFilter.Checked == true)
{
string roomNo = "";
roomNo = DropDownList1.SelectedValue.ToString();
testtable2017 entry = new testtable2017();
SqlConnection dataConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["iPadLoanConnectionString2"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE testtable2017 SET Last_Cleaned_Filter_2017 = '" + Calendar1.SelectedDate.ToString() + "' WHERE Room_No ='" +roomNo +"'";
cmd.Connection = dataConnection;
dataConnection.Open();
cmd.ExecuteNonQuery();
dataConnection.Close();
iPadEntities db = new iPadEntities();
db.testtable2017.Add(entry);
db.SaveChanges();
}
So far so good and it is working perfectly but lets say that when the year changes to 2018 I want to create two more columns that will hold all the data logged within 2018. Is there any way of achieving that and if so how could I also manipulate the code in C# to then start save any data entries to the newly created columns?
Thank you