0

So I am developing a little project in Visual Studio to learn a bit more about SQL, .NET and C#. At the moment i have this block of code that allows me to create two new columns in a database in case the statement is met.:`

int year = 2018;
        Boolean runOnce = true;
        DateTime lastday = new DateTime(year, 1, 1);
        DateTime startDate = new DateTime(year, 1, 1, 0, 0, 0);
        DateTime endDate = new DateTime(year, 12, 31, 23, 59, 59);


if(lastday>=startDate|| lastday<=endDate|| runOnce==true)
            {
                SqlConnection dataConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["iPadLoanConnectionString2"].ToString());
                SqlCommand cmd2 = new SqlCommand();
                cmd2.CommandText = "ALTER TABLE testtable2017 ADD Last_Cleaned_Filter_2018 NVARCHAR(50) ; ALTER TABLE testtable2017 ADD Last_Bulb_Replaced_2018 NVARCHAR(50)";
                cmd2.Connection = dataConnection2;
                dataConnection2.Open();
                cmd2.ExecuteNonQuery();
                dataConnection2.Close();
                runOnce = false;
            }

I also have a GridView in the page that shows the columns of the specific table "testtable2017", my question is, is it possible to refresh the gridview to show the two newly created columns with some code instead of having to refresh schema?

Jorge Guerreiro
  • 682
  • 6
  • 22

0 Answers0